Sunday, February 22, 2009

sample code to demonstrate LinkedHashSet class




package collection;
import java.util.LinkedHashSet;

public class LinkedHashSetDemo {
public static void main(String arg[])
{
LinkedHashSet h=new LinkedHashSet();
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
[b, c, d, null, 10]



0 comments:

Post a Comment