Java : Comparing two ArrayLists, remove values, which are not matching -
i need :
i have object, containing values. of these values equal , differs. based on same values need 2 compare 2 arraylists of these objects. @ least have remove entries aren't stored in both lists.
i wrote function, compares fields in object :
public void comparetwovalues(certainobj1, certainobj2){ boolean returnstmt = true; for(int : keystocheck){ if(!(jop1.returnvalueforkey(i).equals(jop2.returnvalueforkey(i)))){ returnstmt = false; } } return returnstmt; } now have problem, how access , remove objects, function returns false ?
i tried sort them of comparable interface , remove values, got 'concurrentmodificationexception' (yeah, know : used the iterator-loop).
thanks !
arraylist has boolean retainall(collection another) retains elements in collection contained in specified collection. make work in situation create wrapper on original object equals method compares required fields , place wrappers in arraylist.
Comments
Post a Comment