0

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.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by peter_budo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.