I am trying to find duplicate words in a string array.
Here is my code for the comparison:
for ( int j = 0 ; j < wordCount ; j++)
{
for (int i = wordCount-1 ; i > j ; i--)
{
if (stringArray[i].compareTo(stringArray[j]) == 0 && i!=j)
{
//duplicate
duplicates++;
}
}
}
wordCount -= duplicates;
System.out.print("\nNumber of words, not including duplicates: " + wordCount);
in the if statement, it says NullPointerException. What does this mean? Is there a better way to do this? I tried simply doing
if (stringArray[i] == stringArray[j] && i!=j)
but that kept giving me wrong answers.