Have not come to do a good job of the Java collection of commonly used classes, because the interview asked the collection of more in-depth not how to answer well, now come good likes and dislikes to fill.
Java collection classes are primarily derived from 2 interfaces: Collection, Map
The following figure is a set of collection tree, mainly derived from set, List, Queue three major categories
The following figure is a map-derived collection system tree
in this section we only discuss the methods of the collection interface
Add (Object O): This method is used to add an element
AddAll (Collection C): This method adds all the elements in the set C to the specified set
Clear (): clearly set all elements inside the collection
Contains (Object O): Returns whether the collection contains the specified element o
Containsall (Collection C): Returns whether the collection contains all the elements within the specified set C
IsEmpty (): Returns whether the collection is an empty collection
Iterator (): Returns a Iterator object user traversal collection
Remove (Object o): Deletes the specified element o
RemoveAll (collectoin c): Delete all the elements contained within the set C
Size (): Returns the number of elements in a collection
ToArray (): Converting a collection to an array
These methods are commonly used in our approach.
Traversal collection collection mainly useful iterator, for these 2 kinds of
Collection C = new ArrayList ();
C.add ("1");
C.add ("2");
Using iterator to traverse the collection C
Iterator it = C.iterator ();
while (It.hasnext ()) {
System.out.println (It.next ());
}
Using foreach to traverse the collection C
for (Object o:c) {
System.out.println (o);
}
Collection interface is introduced here will be a detailed introduction to set, list, map several commonly used interfaces.