-
The container is also called the collection, can store different types of elements, and the space is multiplied;
650) this.width=650; "Src=" http://note.youdao.com/yws/public/resource/719ed66494263eb983dad4d9b8549a6b/ Eed19747f3d849fd902f5d0453fd229e/01cc7576f44c466f920082e543178f19 "style=" Border:none;height:auto; "alt=" 01cc7576f44c466f920082e543178f19 "/>
Distinction: Collection has no inheritance relationship with map;
Collection Common methods:
Size (): The capacity of the container;
Clear (): Clears all elements in the container;
Add (Object O): Adds any type of element;
Remove (Object o): Removes the specified element;
RemoveAll (Collection C): Removes the specified container;
Contains (Object O): Determines whether a given element is contained in a container;
-
Set interface: Unordered and non-repeatable;
What is disorder? What is the difference between disorder and randomness?
A: The first execution of the code, the output is unordered, and once executed once, the output order will not change, unless the program is added and deleted operations;
Disorder is limited to the first execution, random execution is not the same;
Implementation class: HashSet, TreeSet;
Common construction Methods: New HashSet (); New HashSet (Collection c);
There is no extra method for set, so all of its methods are derived from the method inside the collection;
-
List interface: Ordered can be repeated
Implementation class: ArrayList, LinkedList;
Common methods:
Add (Object c);
Add (int index,object o);//Insert an element o at the specified index;
Remove (Object o);
Remove (int index);//If the container has an integer element, index takes precedence as the subscript index;
Get (int index);//Return object type
Set (int index,object o);//replaces the specified index with the specified element o the element at index;
Size ();//container capacity;
Clear ();//Purge
IndexOf (Object o);//Returns the index value of the first occurrence of the specified element o in the container;
LastIndexOf (Object o);//Returns the index value of the last occurrence of the specified element o in the container;
-
Packaging and Unpacking:
Packaging: Converting the underlying type to an object; integer i=new integer (1);
Unpacking: Converting an object into a basic type; int a=new Integer (1);
-
Iterator:
Iterator: Iterates over an array or container, but unlike a loop, an iteration is traversed only once, and if there is a stop in the middle of the traversal, then the traversal proceeds from where it was last stopped, rather than starting from the beginning of the loop;
The collection interface has the iterator () method by default;
Common methods:
Hasnext ();//Determine whether there are elements on the right side of the cursor;
Next ();//Returns the object type, given the specific element value of the container, and continues to judge the next time;
Remove ();
-
Enhanced for Loop foreach:
Syntax: for (type variable name: Array or container name) {< output variable name can traverse;}
Pros: Traverse extremely fast
Disadvantage: There is no subscript, can not be used to sort, except traversal, no other method is provided;
-
Generic type:
Why is there a generic type?
A: Let the specified type become unique, can improve the efficiency of the Code;
Syntax: Class name < app Type > object name =new class name < reference type > ();
-
Equals () and Hashcode () methods:
Note: When an object exists, remember to rewrite equals () and hashcode ();
Equals (): is only responsible for comparing the values of two objects for equality;
Hashcode (): Determines whether two objects point to the same object (reference) and returns a hash code value;
-
Map Interface:<k,v>;
Key cannot be duplicated;
Implementation class: HashMap, TreeMap, Linkedhashmap;
Common methods:
Put (Object K,object v);
Get (Object key);//Returns the value mapped by key
ContainsKey (Object o);//Determines whether the given element o is contained in the container, and if so, returns true;
Containvalue (Object o);//Determines whether the value in the container contains the given element O, and returns true if yes;
Remove (Object o);//delete the given element;
This article is from the "Kun" blog, please be sure to keep this source http://linyingkun.blog.51cto.com/2393912/1575543