The Java collection is divided into three main types: The Java collection is located in the Java.util package set (SET) list (list) map (map) arrays function, Equals (): Compares two arrays for equality. Fill (): Fills the value into the array. Sort (): Used to sort the array. BinarySearch (): Looks for elements in a sorted array. Arraycopy (): Copy of Array. Collection classification: Collection, List, set, map are all interfaces and cannot be instantiated. Collection:list, set, Collection is the most basic method of the collection interface Map:hashmap, Hashtablecollection interface: Boolean Add (Object O): A reference to an object in the collection void Clear (): Deletes all objects in the collection, i.e. no longer holds references to these objects, Boolean isEmpty (): Determines whether the collection is empty Boolean contains (object O): sentenced Whether a reference to a particular object is held in the collection Iterartor iterator (): Returns a Iterator object that can be used to traverse the elements in the collection, Boolean remove (Object o): Removes a reference to an object from the collection in T size (): Returns the number of elements in the collection object[] ToArray (): Returns an array that includes all the elements in the collection iterator interface: Hasnext (): Determines whether the elements in the collection are traversed Completion, if not, returns True Next (): Returns the next element, remove (): Removes the element from the collection that was returned by the next () method. Set: There is no need for the Hashset:hashset class to access the objects in the collection according to the hashing algorithm, the access speed is faster than the Treeset:treeset class implements the SortedSet interface, and the objects in the collection can be sorted. Linkedhashset: has hashset query speed, and internally uses the chain list to maintain the order of elements (the Order of insertions). List interface: Linear repeatable ArrayList (): Indicates the length can be changed by the group. Elements can be randomly accessed, and it is slow to insert and delete elements into ArrayList (). LInkedlist (): A linked list data structure is used in the implementation. Fast insertion and deletion, and slow access times. Vectorlist traversal: 1:for loop and Get () method: for (int i=0; i<list.size (); i++) {System.out.println (List.get (i)); } 2: Using Iterators (Iterator): Iterator it=list.iterator (); while (It.hashnext ()) {System.out.println (It.next ()); Map: Map does not inherit from the collection interface, which belongs to the independent branch. Object put (object key, Object value): Adds an element to the collection object remove (Object key): Removes the element associated with key void Putall (Map t): All meta-elements from a particular image The element is added to the image void Clear (): Removes all mappings from the Image object get (Object key): Gets the value associated with the keyword Key containskey () and Containsvalue () test map contains a "key" or "value" "Map: No need for No duplicates (key), similar to set HASHMAP:MAP based on the implementation of the hash table." Single thread in map<string, string> Map = new hashmap<string, string> (); LINKEDHASHMAP: Maintains internal order using a list of links. TREEMAP: Based on the implementation of red-black tree data structure. Single thread in map<string, string> Map = new treemap<string, string> (); HashTable: General usage of map in multi-Threading 1. Declare a map:map map = new HashMap (); 2. Place values in map, note: Map is a map.put ("sa", "dd") stored in key-value form, and 3. Value from map: String str = map.get ("sa"). ToString, the result is: str = "DD" 4. Traverse a map to get key andValue:map m= new HashMap (); For (object Obj:map.keySet ()) {Object value = Map.get (obj);} Traverse Hashmapfor (String key:map.keySet ()) {value = Map.get (key);} For (entry<string, string> entry:map.entrySet ()) {key = Entry.getkey (); Value = Entry.getvalue ();} For (String value:map.values ()) {} traversal Treemap:for (String Key:map.keySet ()) {value = Map.get (key);} For (entry<string, string> entry:map.entrySet ()) {key = Entry.getkey (); Value = Entry.getvalue ();} For (String value:map.values ()) {}
Java Collection Class (2)