In the Java Collection frame, the SET series is the simplest, the SET interface, and the Collection interface, AbstractSet is equally simple, only three implementations, here is listed one by one.
Public Boolean Equals (Object O) {IF (o == this) Return True;
IF (! (o instanceof set) Return False; Collection C = (Collection) O; if (C.Size ()! = size ()) Return False; try {return containsall (c);} catch (classcastexception unused) {RETURN FALSE;} Catch (nullpointerException) {returnte false;}} is really simple, basically calling the ContainsAll method, because if the two sets are the same size, one contains another, etc., here must wait, here to capture Two systems are abnormal, and return directly to false.
Public int hashcode () {int h = 0; Iterator i = item (); while (I.hasNext ()) {Object Obj = I.next (); if (Obj! = null) h = obj.hashcode );} Return h;} is simpler, all of the HashCode added.
Public Boolean Removeall (Collection C) {Boolean Modified = FALSE
IF (size ()> c.size ()) {for (Iterator i = C.Iiterator (); I.hasNext ();) Modified | = remove (i.next ());} else {for (Iterator i = iTerator (); I.hasNext ();) {if (c.contains (i.next ())) {i.remove (); modified = true;}}} return model
It is always traversed here. If C is smaller than this set, it traverses C. The REMOVE method is called, but modified | = relatively powerful, as long as there is a deletion, Modified is True. If C is greater than this set, it will traverse yourself if you exist in C.
This can improve efficiency: After using hash lookup, the Contains method time complexity should be constant, so picked smaller collection traversal can improve efficiency. If contains are not Hash lookup, it is the same.