Home Tutorial Java Scjp Part9 SCJP Module-9 Question-1

 
 

Share on Google+Share on Google+
SCJP Module-9 Question-1
Posted on: July 16, 2010 at 12:00 AM
Advertisement
The sample program given below your knowledge of HashSet class of collection framework.

Given below the sample code :

import java.util.HashSet;
public class CollectionExample {
public static void main(String ... args) {
HashSet<String> hs = new HashSet<String>();
String str1 = new String("Buzz");
String str2 = new String("Buzz");
hs.add(str1);
hs.add(str2);
System.out.println(hs);
}
}

What will be the output of the following ?

1. Compilation error

2. [Buzz,Buzz]

3. [Buzz]

4. Buzz

Answer

(3)

Explanation

The 'HashSet' doesn't allow to store duplicate collections. That's why 'Buzz' is stored once in HashSet 'hs'.

Advertisement

Related Tags for SCJP Module-9 Question-1:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 16, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com