A collection of List, Set, and Map
Java collections are divided into three types: list, set, and map. Both list and set inherit from the Collection interface. The biggest difference between them is that set cannot contain duplicate elements.
Common list Implementation classes include:
ArrayList: Variable-size array implementation; linked list implementation; fast addition and deletion of elements; slow search; Vector: thread-safe implementation of Variable-size Array
List commonly used methods include:
Add (E); // add the specified clear () element to the end of the list; // remove all elements from the list contains (Object o ); // determine whether the list contains the specified Element get (int index); // return the element at the specified position in the list. IsEmpty (); // returns trueiterator () if the list does not contain elements; // returns the iterator remove (int index) containing all elements in the list ); // remove the element set (int index, E element) at the specified position in the list; // Replace the element size () at the specified position in the list with the specified element (); // return the number of elements in the list toArray (); // return the array containing all elements in the list
Common set implementation classes include:
HashSet: set based on the hash algorithm segment HashSet: set based on the hash and linked list algorithms TreeSet: sortable set based on the Binary Tree Algorithm
Common Methods of set are:
Add (E); // if no specified element exists in the set, add this element addAll (Collection c); // if no element in the collection is specified in the set, then add it to this set (intersection operation) clear (); // remove all elements in this set contains (Object o); // If the set contains the specified element, returns trueisEmpty (); // If the set does not contain elements, returns trueiterator (); // returns the iterator remove (Object o) that contains all elements in the set ); // If a specified element exists in the set, remove removeAll (Collection c); // remove the elements contained in the set in the specified collection (differential set Operation) retainAll (Collection c); // only keep the elements in the set that are included in the specified collection (union operation) size (); // return the number of elements in the set toArray (); // returns an array containing all elements in the set.
Common map implementation classes include:
HashMap: Implement Hashtable Based on hash map: Implement thread-safe map based on hash
Common map methods include:
Clear (); // remove all containg containsKey (Object key) from this ing; // determine whether the map contains the specified keyentrySet (); // return the get (Object key) set containing all the elements in the Map; // return the isEmpty () value mapped to the specified key; // If the map does not contain elements, returns truekeySet (); // returns the Set view put (K key, V value) of the key contained in the ing; // adds the key-value Pair remove (Object key ); // remove the specified keysize (); // return the total number of values () of the key-value pairs in the map; // return the Collection view of the values contained in the ing.
Arrays
AsList (T... A); // convert the specified array to the list object binarySearch (...); // Use the binary search method to find the specified object. Sort the array equals (…) before use (...); // Compare whether the two arrays are consistent with fill (...); // Replace all elements in the array with the specified value sort (...); // Sort the Array
You can use System. arraycopy (…) to copy an array (...) Method
Iterator
HasNext (); // returns true next () if there are still elements that can be iterated; // returns the next element of the iteration remove (); // removes the last element returned by the iterator
Collections
Sort (...); // Sort the specified set and reverse (...); // The sequential shuffle (…) of the flipped set (...); // Random replacement fill (…) for the position of the specified set (...); // Replace all elements in the set with the specified value max (...); // Returns the maximum element min (…) in the set (...); // Return frequency (…), the smallest element in the set (...); // Returns the number of times the specified value appears in the set. synchronizedList (...) , SynchronizedSet (...) , SynchronizedMap (...); // Return the List, Set, or Map unmodifiableList (…) that supports synchronization (...) , UnmodifiableSet (...) , UnmodifiableMap (...);
// Return unmodifiable List, Set, or Map