I have seen an exaggerated saying, "People who have not read the jdk source code are not considered to have learned java." Start intensively reading the source code from today. The source code suitable for intensive reading is nothing more than the classes packaged by java.io, .util and .lang.
There are still many examinations on sets in the interview questions, so I will start with the source code of the set.
(1) First of all, the Collection interface.
Collection is the root interface of all collection classes; Collection inherits Iterable, that is, all classes in Collection can use the foreach method.
/** * Collection is the root interface of all collection classes; * Collection inherits Iterable, that is, all classes in the Collection can use the foreach method. * @author WGS * @param <E> */public interface Collection<E> extends Iterable<E> {//Return the size of the element in the collection. (If this size value exceeds Integer.MAX_VALUE, it will directly return Integer.MAX_VALUE) int size();//Judge whether the set is empty Boolean isEmpty();//Judge whether the set contains element o (note whether element e is null and whether type compatibility issues) Boolean contains(Object o);//Return the iterator of the elements in the set (order cannot be guaranteed unless the set specifies the order) Iterator<E> iterator();//Return all elements in the set in the form of an array, and the array is safe Object[] toArray();//Return the set element of the specified array type in the form of an array <T> T[] toArray(T[] a);//This method can be used to determine whether the set contains element e; yes -false, no-true (this method is often called in set, map, which is very useful in programming questions) Boolean add(E e);//Remove the specified element from the set Boolean remove(Object o);//Use to determine whether the element Boolean containsAll(Collection<?> c);//Add all elements in the specified set to the caller's collection Boolean addAll(Collection<? extends E> c);//Remove the same element as the specified set (that is, remove the intersection part of the two sets) Boolean removeAll(Collection<?> c);//Remove all elements in the specified set (that is, remove the intersection part of the two sets) Boolean removeAll(Collection<?> c);//Remove all elements in the specified set to the caller's collection Boolean addAll(Collection<?> c);//Remove the same element as the specified set (that is, remove the intersection part of the two sets) Boolean removeAll(Collection<?> c);//Retain the same elements as in the specified set (that is, remove elements that are different from the specified set) Boolean retainAll(Collection<?> c);//Clear the set void clear();//Defend whether it is equal to the specified element Boolean equals(Object o);//Return the hash code value of the set int hashCode();}Summarize
The above is all the content of this article about the detailed explanation of jdk source code reading collection, I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!