How to remove duplicate and null from the list.

Hi All,

I have a list which contains duplicates and null value. How to remove null and duplicates to get unique list without null? I tried but I am getting NullPointerError

List l = new ArrayList();
l.add(1);
l.add(2);
l.add(2);
l.add(6);
l.add(null);
l.add(null);

	Set<Integer> s = null;
	if(l != null){
	 s = new TreeSet<Integer>(l);
	}
	
	for(Integer ii: s){
		System.out.println(ii);
	}

Appreciate Your help!

Regards,
Meharaj

s = [6, 7, 8, 9, 8, 9, 10, 10, 11, 12, 9, 10, 11, 11, 12, 13, 12, 13, 14, 15]

And the ouput should be like this:

s = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

I know a way in pyhton like this:

s = [6, 7, 8, 9, 8, 9, 10, 10, 11, 12, 9, 10, 11, 11, 12, 13, 12, 13, 14, 15]
s = list(dict.fromkeys(s))
print(s)

ArrayList l = new ArrayList();
l.add(1);
l.add(1);
l.add(2);
l.add(2);
l.add(3);
l.add(3);
Set s = new HashSet(l);
System.out.println(s);
you can try this