sample code to demonstrate HashSet class
package collection;
import java.util.HashSet;
public class HashSetDemo {
public static void main(String arg[])
{
HashSet h=new HashSet();
System.out.println(h.add("b")); // true
h.add("b");
h.add("c");
h.add("d");
h.add(null);
h.add(new Integer(10));
System.out.println(h.add("d")); // flase
System.out.println(h); // depends on hash code number insertion order.
}
}
output:
true
false
[d, null, c, 10, b]
0 comments:
Post a Comment