Set is also inherited from Collection,set, which is also a collection, and set does not allow duplicate elements to exist.
Set source code:
Public Interfaceset<E>extendscollection<E> {intsize(); //Size BooleanIsEmpty();//Is empty Booleancontains(Object o); //Whether an object is included iterator<E>iterator(); //Generate iterators Object[]ToArray(); //Returns an object array <T>T[]ToArray(T[] a); //return generic array BooleanAdd(EE; //Add elements to set BooleanRemove(Object o); //Remove an element from the set BooleanContainsall(collection<?> c); //Whether a collection is included in this LSet BooleanAddAll(COLLECTION<?extendsE> C); //Append a collection to this set BooleanRetainall(collection<?> c); //delete elements in a set that do not exist in collection BooleanRemoveAll(collection<?> c); //Delete the elements contained in this collection voidClear(); //Empty set Booleanequals(Object o);//Determine if two sets are the same inthashcode(); //Calculate set's Hashcode @Override defaultspliterator<E>Spliterator() {returnSpliterators.spliterator (This ,SPLITERATOR.DISTINCT); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java-set Source Code Analysis