Java Collection Class collation

Source: Internet
Author: User

Tag:java    collection    

Collection:set (interface) abstractcollection (abstract class) Abstractlist->list Abstractsequentiallist LinkedList (implements the Deque dual-ended queue interface) Vetor<-stack ArrayList Abstractset (implements the set interface) T   Reeset: Implemented the Navigableset->sortedset->set list (interface) queue (interface) interface Collection Set list queue SortedSet         Navigableset Analysis: 1: All classes or interfaces are implemented collection interface 2:treeset,hashset,linkedhashset implementation of the set interface, where TreeSet implements SortedSet 3:arraylist,vector,linkedlist implements the list interface java.util.Collection the root interface of all collections is incremented: Add (o:e): Boolean addal L (c:collection< extends e>): Boolean remove Remove (O:E): Boolean RemoveAll (c:collection<?>): Boolea    N Clear (): Boolean modified: Check: Contains (O:object): Boolean Containsall (c:collection<?>): Boolean         Other: Equal (O:object) hashcode (); INT//Returns the hash code of the collection size (): int ToArray (): object[]//Returns the array form of the collection       IsEmpty () Iterator ():interator<e>//Returns an iterator note: The Iterator Interface Hasnext () Next () Set set interface expands the collection interface. It does not introduce new methods or constants, only specifies that the instance of set does not contain duplicate elements 1,set interface relies on hashcode and equals () to complete the judgment of repeating elements, and this concern is also reflected in the future map interface 2,treeset rely on comparable Interface to complete the sort operation when the 3,set method is used, when the element is a custom class, the custom class wants to diarrhea equals () in the object class, Hashcode (), ToString () method 4, which implements the class Hashset,treeset,linke Dhashset 5, especially note that there are no duplicate elements in the ruleset, so adding duplicate elements will return false, but there will be no exception hash set Java.util.HashSet initial capacity is 16, the guest rate is 0.75 when the number of elements exceeds the capacity * guest rate        Product, the capacity is automatically doubled to initialize HashSet () HashSet (c:collection<? extends e>) HashSet (initialcapacity:int) HashSet (Initialcapacity:int,loadfactor:float) Method: Implements the method in the collection interface chain hash table linkedhashset with a list to expand HASHS ET, which supports ordering elements within a ruleset (so-called ordering is stored in the order of addition, and is accessed in the order of addition).    Elements in HashSet are not sorted, while elements in Linkedhashset can be extracted in the order they are inserted in the rule set. Initialize: Linkedhashset () Linkedhashset (c:collection<? extends e>) Linkedhashset (initialcapacity:int ) Linkedhashset (initialcapacity:Int,loadfactor:float) Method: Implementation of collection method set method does not have access to the index method, only Add,remove,contains class method tree set TreeSet sortedset is SE A sub-interface of T, which ensures that elements in the ruleset are ordered. In addition, it provides a method First,last method to return the first and last of the ruleset, as well as methods headset ((toelement)) and tail (fromelement) Returns a portion of the ruleset that is less than toelement or greater than or equal to Fromelement Navigableset extends SortedSet and provides navigation methods lower (e), Floor (e), ceiling (e), Higher (e) Returns less than, less than or equal to, greater than or equal to, and greater than the element of the given element. If not, returns NULL. Pollfirst,polllast will delete and return the first and last element of the tree set respectively TreeSet is a concrete class of sortedset, the element must be comparable, that is, the element implements the comparable interface or is specified by the comparator to summarize the method T            Reeset Common method: Set self-perception provides a kind of storage services, is not good at locating this location, so his storage is unordered, so the method is not the same as the list, do not need to have the index parameter initialization TreeSet () TreeSet (c:collection<? extends e>) TreeSet (comparator:comparator<? Super E>) Tr Eeset (s:sortedset<e>) added: Add () addall () Delete: Remove () Remo             Veall () Clear () Modify: Find: Contains () Containsall () Other (length, iterator, hash code, etc.): SIze (); ToArray () IsEmpty () iterator () equals () Hashcode () TreeSet Special method (implements the interface sorted            Set and Navigableset methods): Note: When using these methods, the type of the defined object must be SortedSet incremented: no Delete: Pollfirst () Polllast () Lookup: The first element of the navigation method: initial ()//empty set and when an exception tail element is thrown: last () Small     Set of E HeadSet ():sortedset<e>//Does not exist returns an empty set greater than or equal to E tailset ():sotedset<e>//does not exist return empty sets greater than E            Higher (e)//does not exist return null greater than or equal to ceiling (e)//does not exist return null less than lower (e)//does not exist return null is less than or equal to floor (e)//does not exist return NULL modification: Other: Tips: 1, when defining hashset, you can use set<e> SE t = new hashset<e> () definition 2, when defining TreeSet, the last direct use of treeset<e> set = new treeset<e> () comparable interface bit    To Java.lang public interface companrable<t>{public int compareTo (T o); }comparator interfaces sometimes want to insert elements into a tree collection, and these elementsMay not be an instance of java.lang.comparable, you can define a comparer to compare these elements.    To do this, create a class for the Java.util.Comparator interface. Comparator interface has two methods: public int Compare (object E1,object E2) public boolean equals (object e) Linear table rule set can only store non-duplicates    values, in order to store duplicate values, need to make the employee linear table. The list interface extends the collection interface to define an ordered set of allowed duplicates.            The list interface adds position-oriented operations, and adds an iterator method that can traverse a linear table in two directions: 1, you can use Method 2 in collection, the operation is divided into element-oriented and location-oriented methods to increase: Add (Index:int): Boolean add (index:int,c:collection<? extends e>) adding (E)//End adds  All (c:collection<? extends e>); Add Delete at the end: Remove (index:int) Remove (o) RemoveAll (c) Modify: Set (Inde X:INT,E): E-Find://Find element Get (Index:int): E contains (O): Boolean contains (c): Boolean//index-oriented indexOf (e) lastIndexOf (e) Other listiterator (): Listiterator           <E> listiterator (startindex:int):listiterator<e> Sublist (Fromindex:int,toindex:int):list<e>//Returns a sub-list from FromIndex to ToIndex-1 java.util.ListIterator Add (o:e): Voi D Backwards: Hasnext (): Boolean Next (): E nextindex (): Int//Returns the subscript of the next element Remov            E (): Void Forward: Hasprevious () Previous () Previousindex (): Index//Returns the subscript of the previous element Set (E): void//Use the specified element to replace previous or next to return the last element of the array linear table ARRAYLISTJAVA.UTIL.ARRAYLIST&LT;E&GT;: Initialize: list<e>        List = new arraylist<e> ();    Arraylist<e> () arraylist<e> (c:collection<? extends e>) arraylist<e> (capacity:int) Added: Add (o:e): void Add (index:int,o:e): void//Insert Element Delete: Remove (O:E): Boolean Remove (Index:int): boolean//index must be reasonable, otherwise there is an exception to the clear () Modification: Set (index:int,o:e): E//index must be reasonable, otherwise there is an exception to check: Get (index:int): E indexOf (o:e): Int//does not exist return-1 lastIndexOf (O:E): Int//does not exist return-1 contains (O:E): Boolean IsEmpty (): Boolean Length: Size () automatic decrease of linear table will not automatically decrease, only automatically increase trimtosize ()//capacity to decrease the current size of the list line        The table LinkedList implements the list interface and the queue interface initialization LinkedList () LinkedList (c:collection<? extends e>) Increase:        Addfist (O:E)//Add to List header AddLast (o:e)//Add to List footer//list method Add (Index) Add (index,e)        AddAll (c) Delete Removefirst () removelast ()//list Remove (index) find GetFirst () GetLast ()//list get (Index) indexOf (e) lastIndexOf (e) Other//list Listitera     Tor ():listiterator<e> listiterator (Index):listiterator<e> () sublist (start,end);        Start~end-1collection static method ordering (improved merge sort) sort (list:list): void Sort (list:list,c:comparator): void lookup BinarySearch (List,key) binarysearch (list,key,comparator) reverse reverse (list) reverse reverseorder (); /return inverse comparator randomly disrupts shuffle (LIST) Shuffle (LIST,RANDOM)//Shuffle replication Copy with random objects (des:list,src:list): void Ncopies (n:int,o:object): List Returns the list of n copies of O fill Fill (list,o)//Replace all elements in a linear table with the specified element max (c:collection): Object Max (c:collecti On,c:comparator): Object min min (c): Object min (C1,C2): Object An element occurrences frequency (c:collection,o:ob  ject): the int vector class vector is almost the same as ArrayList, just add the synchronous method to implement the list method to initialize vector () vector (c:collection<        Extends e>) Vector (initialcapacity:int);        Vector (Initialcapacity:int,capacityincr:int) added: AddElement (o:e) insertelementat (o:e,index:int) Delete        Removeallelements () removeelement (o) removeelementat (index) Modified: Setelementat (O,index) find Firstelement () lastelement () elementat (index) stack stack () empty () pop () push () Peek (): Return return stack top element search (O): Returns the position of the specified element in the stack queue offer (E): Inserts an element into the queue poll (): Out of line, null when empty REmove (): Out of the queue, empty when the exception peek (): Gets the first element of the team, returns null element when empty (): Gets the first element of the team, the exception occurs when the Deque double-ended queue LinkedList implements the Deque interface, so you can use Linke    Dlist Create a double-ended queue AddFirst () addlast () Removefirst () Removelast () GetFirst () GetLast () Map for storing data in the form of key-value pairs            The map interface provides a method to query get (key): V values ():collection<v> keySet ():set<k> EntrySet ():set<map.entry<k,v>> ContainsKey (Key): Boolean Containsvalue (value): Boole An isEmpty () size () add put (key,value) put (map) remove REM    Ove (Key) Clear () modify Hashmaplinkedhashmap use the linked list implementation to extend HASHMAPTREEMAP efficiency when traversing the ordered key values There are new navigation methods Firstkey () Lastkey () Headmap (Tokey) tailmap (Fromkey) Floorkey (key) Ceill Ingkey (Key) Lowerkey (key) Higherkey (key) attached: Map traversal method set<map.entry<k,v>> Set = Map.entr        Yset (); for (MAP.ENtry<k,v> m:set) {key=m.getkey ();        Value=m.getvalue (); }

Java Collection Class collation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.