Identical Linked Lists | A recursive Java method to check if two linked lists are identical or not ; If both lists are empty ; If both lists are not empty , then data of current nodes must match , and same should be recursively true for rest of the nodes . ; If we reach here , then one of the lists is empty and other is not ; Returns true if linked lists a and b are identical , otherwise false
boolean areIdenticalRecur ( Node a , Node b ) { if ( a == null && b == null ) return true ; if ( a != null && b != null ) return ( a . data == b . data ) && areIdenticalRecur ( a . next , b . next ) ; return false ; } boolean areIdentical ( LinkedList listb ) { return areIdenticalRecur ( this . head , listb . head ) ; }