Hello,

I am writing a while loop that will run as long as the cell in the array is not equal to the object element. However, using the .equals method I cannot find a way to do so so that the loop uses not equals to compare the object to keep the loop going through the array. So basically, I have an array filled with objects, I want the while loop to go through the array checking objects in each cell of the array to compare with a given element. If the loop finds a match in the array, it needs to exit the loop. Here is the loop header, but I really cannot see a way to do it using not equals instead of equals, therefore I cannot get it to work.

while(array[i].equals(element))

How do I make this so continues as long as the array and element are not equal to each other. != does not work on objects, and I read somewhere you can put a ! in front of equals, but that didn't work either. Please help me with this issue.

Thank you in advance for any help.

while(!array[i].equals(element))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.