So I have String array that looks like this:
arraySubs:
math
math
math
web
web
web
prog
prog
prog
Now I want to remove the duplicates to look like this:
arraySubs:
math
web
prog
I wouldn't mind if there is null on places that should be removed, so I tried this:
for(int j = 0; j < arraySubs.length; j++) {
if(j<arraySubs.length-1) {
if(arraySubs[j+1]==arraySubs[j]) {//equalsIgnoreCase doesn't work.
arraySubs[j]=null;
}
}
if(arraySubs[j]!=null) {
System.out.println(arraySubs[j]);
}
}
But it doesn't work it's still printing all of them, any ideas? I don't wanna use Set, HashSet etc. Or any other tools such as iterators. equals() doesn't work...