1. Overview of the collection
The difference between sets and arrays. |
Collection-specific traversal method. |
public static void Main (string[] args) {
//Create collection Object
Collection c = new ArrayList ();
Create and add element
c.add ("Hello");
C.add ("World");
C.add ("Java");
Traversal collection
Iterator it = C.iterator ();
while (It.hasnext ()) {
string s = (String) it.next ();
System.out.println (s);
}
2, List and set Overview
List and set differences. |
3, List
List features and implementation classes |
For knowledge of thread safety, refer to http://blog.csdn.net/qq_34149805/article/details/64128499
For the knowledge of the linked list, refer to http://blog.csdn.net/qq_34149805/article/details/67117288 4, Set
The set has exactly the same interface as collection, so there is no additional functionality, unlike the two different lists that preceded it. In fact set is collection, but behavior is different. (This is a typical application of inheritance and polymorphic thinking: behavior that behaves differently.) Set does not save duplicate elements (more responsible for determining the same element)
Each element of a set stored in a set must be unique because the set does not save repeating elements. Elements that join a set must define the Equals () method to ensure the uniqueness of the object. Set has exactly the same interface as collection. The set interface does not guarantee the order of elements to be maintained.
5, Summary
ARRAYXXX: The underlying data structure is an array, query fast, additions and deletions slow
linkedxxx: The underlying data structure is linked list, query slow, additions and deletions quickly
hashxxx: the underlying data structure is a hash table. Relies on two methods: Hashcode () and Equals ()
treexxx: The underlying data structure is a two-fork tree. Sort in two ways: natural sort and comparer sort
RELATED LINKS Java Map Super verbose rollup