0

Hello again. :)
I am comparing two nodes (some of my other methods need this method). I am having a problem with this method because it returns false even though both nodes have the same content. What are the problems of this code? Any suggestions? This is the critical part of my code.

By the way, here's the code:

public boolean equals(Object o){		
		if(o instanceof Node){ //checks whether the object is an instance of Node
			System.out.println("Entering the first if statement"); // meaning o is an instance of Node
			if(((Node)o).elname == this.elname && ((Node)o).efname == this.efname && ((Node)o).work == this.work && ((Node)o).floorno == this.floorno){ //checking the contents of Nodes
				System.out.println("Entering the 2nd if and returned true"); //Contents are the same
				return true;
			}else{
				System.out.println("Entering the second if and returned false"); //contents are different
				return false;
			}
		}else{
			System.out.println("Entering the first if and returned false"); //O is not an instance of Node
			return false;
		}
	}
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by chixm8_49
0

If some of those "things" are Strings, use String's equals method rather than == to compare them. (I'm assuming efname is a String.)

Edited by masijade: n/a

0

If some of those "things" are Strings, use String's equals method rather than == to compare them. (I'm assuming efname is a String.)

*cries for joy*
It works! Thank you very much! :)

This question has already been answered. 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.