import java.util.*;
class Sample
{
public static void main(
String[] args)
{
//TREESET ACCEPTS DUPLICATES
TreeSet ts = new TreeSet();
ts.add("one");
ts.add("one");
//HASHSET ACCEPTS DUPLICATES
HashSet hs= new HashSet();
hs.add(null);
hs.add(null);
//HASHMAP ACCEPTS DUPLICATES
HashMap hm = new HashMap();
hm.put(null,null);
hm.put(null,null);
//TREEMAP ACCEPTS DUPLICATES
TreeMap tm = new TreeMap();
hm.put("one",null);
hm.put("one",null);
}
}
This is the program which I tried out with main classes in util package with nulls and duplicates.
In
java API and other available sources in the net says Set interface wont allow duplicates,so also Map wont allow duplicate keys but my program is compiling and running without any errors.In the case of Map it is just overriding the previous key.I am using jdk1.3.Please clarify.
Thanx in advance,
Vinod Pai