HashSet
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
C:\jdk1.2.1\bin>java SetApp
The size of the set is: 5
a
test
This
is
null
I think Output should have been
This
is
a
null
Test
Can any colleague kindly guide me, as to why the program output is not as I had expected it to be*/
import java.util.*;
public class SetApp {
public static void main(String args[]){
HashSet set = new HashSet();
set.add("This");
set.add("is");
set.add("is");
set.add("a");
set.add("a");
set.add(null);
set.add("test");
displaySet(set);
}
static void displaySet(HashSet set) {
System.out.println("The size of the set is: "+set.size());
Iterator i = set.iterator();
while(i.hasNext()){
Object o = i.next();
if(o == null) System.out.println("null");
else System.out.println(o.toString());
}
}
}
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Bill
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by ZEESHAN AZIZ:
/*Dear Fellows, on compiling this program I am getting an output
C:\jdk1.2.1\bin>java SetApp
The size of the set is: 5
a
test
This
is
null
I think Output should have been
This
is
a
null
Test
Can any colleague kindly guide me, as to why the program output is not as I had expected it to be*/
import java.util.*;
public class SetApp {
public static void main(String args[]){
HashSet set = new HashSet();
set.add("This");
set.add("is");
set.add("is");
set.add("a");
set.add("a");
set.add(null);
set.add("test");
displaySet(set);
}
static void displaySet(HashSet set) {
System.out.println("The size of the set is: "+set.size());
Iterator i = set.iterator();
while(i.hasNext()){
Object o = i.next();
if(o == null) System.out.println("null");
else System.out.println(o.toString());
}
}
}
| These are not the droids you are looking for. Perhaps I can interest you in a tiny ad? The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






