Problem in checking if 2 Linked Lists are containing same values in java

I was asked to write a method that runs on a Linked List and checks if 2 of the lists contain the same values (It doesn't have to be the same order of values between them both). Here's my code:

public boolean Equals(Object obj) {

if(obj instanceof LinkedList) //Checks if the object it got is a Linked List


if(this.length() != ((LinkedList)obj).length())

return false;

Node head1 = head;

Node head2 = ((LinkedList) obj).getHead();

boolean ans = false;



while(head1 != null)// Running on the 1st list values


while(head2 != null) { // comparing each value in the 2nd list to see...

Read More »

By: StackOverFlow - Tuesday, 8 January

Related Posts