The HashSet Set implementation allows the addition of null. Is there any Collection implementation that will not allow null? I know I can do a remove for the null on the HashSet, but I was wondering if I can restrict it.
public static void main(String[] args) {
Set<String> testing = new HashSet<String>();
testing.add(null);
testing.add("test");
for(String str : testing){
}
}
//TreeSet allows null as well
public static void main(String[] args) {
TreeSet<String> testing = new TreeSet<String>();
testing.add(null);
for(String str : testing){
System.out.println("testing");
}
}