Possible Duplicate:
How do I compare strings in Java?
I have written this code:
public String[] removeDuplicates(String[] input){
int i;
int j;
int dups = 0;
int array_length = input.length;
for(i=0; i < array_length; i++){
//check whether it occurs more than once
for(j=0; j < array_length; j++){
if (input[i] == input[j] && i != j){
dups++; //set duplicates boolean true
input[j] = null; //remove second occurence
} //if cond
} // for j
} // for i
System.out.println("Category contained " + dups + " duplicates.");
return input;
}
which is supposed to check whether an array of strings contains one or more duplicates. However, even when I define the array like this:
String[] temp = new String[2];
temp[0] = "a";
temp[1] = "a";
The if condition is not "triggered". Did I misunderstand how && works? In my opinion, the program should first check whether the two strings are identical (which they are...) and then whether the two indices are the same. If not, it should perform the operations. However, the programs seems to think otherwise.