Arrays.equals not returning correct answer.
Hi,
I am having some problems with Arrays.equals. I can't get it to return true and I can't see the problem.
Code :
public void testing()
{
boolean check = Arrays.equals(test, test2);
if (check == false)
{
System.out.println("Word is not a palindrome!");
for ( int i=0; i < test.length; i++){
System.out.println(test[i] + " " + test2[i]);
}
}
else
{
System.out.println("Word is a palindrome!");
for ( int i=0; i < test.length; i++){
System.out.println(test[i] + " " + test2[i]);
}
System.out.println("Isn't this an exciting game!");
}
}
test is a word input by the user, test2 is test copied to test2 and reversed. If I print the arrays they seem to be the same. If i change it to compare test to test or test2 to test2 it tells me they are the same so I guess I am just missing something. Can anyone point me in the right direction?
Thanks
Re: Arrays.equals not returning correct answer.
I suspect the problem may be that you have capital and lower-case letters? Java is case sensitive.
Re: Arrays.equals not returning correct answer.
Maybe the fact that you're reversing one of the arrays is making them not equals each other any more.
// Json