String target = JOptionPane.showInputDialog("Please enter the string you are looking for");
Node current = top;
int counter = 0;
while (current != null) {
if (current.getElement() == (target)) {
printTextField.setText(target + " was found, its position is: "+ counter);
} else {
System.out.println("not found: "+current +" "+target);
current = current.getNext();
counter ++;
}
}
As you can see I am trying to search for a certain string in a stack.
My stack looks as followed : One, Two, Three, Four, Five.
Method is comparing the values as followed: not found: menuGUI$Node@4ae17538 Three
When using .equals the program is just looped for eternity.