The collection and map interfaces are provided in Java. List and set inherit the collection interface, and use the vector, arraylist, and sorted List classes to implement the list interface, while hashset and treeset implement the set interface. Hashtable, hashmap, and treemap are directly used to implement the map interface.
Vector is an array-based list, and its performance cannot surpass that of array. vector is "sychronized", which is the only difference between vector and arraylist.
Arraylist: Like a vector, It is array-based, but the difference is that arraylist is not synchronized. Therefore, the performance is better than that of vector.
Sort list: Unlike the previous two lists, it is not based on array, so it is not limited by Array Performance. You only need to modify the relevant information of nextnode when adding and deleting the nextnode list. Therefore, it is suitable for frequent insert and delete operations. This is the advantage of listing.
List:
1. All lists can only contain tables composed of a single object of different types, rather than key-value pairs. Example: [Tom, 1, C];
2. All lists can have the same elements. For example, the vector can have [Tom, koo, too, koo];
3. All lists can have null elements, such as [Tom, null, 1];
4. array-based list (vector, arraylist) is suitable for queries, while sorted list (linked list) is suitable for adding and deleting operations.
Although set and list all implement the collection interface, their implementation methods are quite different. List is basically based on array. However, set is implemented based on hashmap, which is the fundamental difference between set and list.
Hashset: the key in hashmap is used as the corresponding storage item of the set. The key of hashmap cannot be duplicated. Hashset can be used to quickly locate an element, but the hashcode () method 0 must be implemented for objects placed in hashset.
Treeset: stores the elements in the table in order, which requires that the objects in the table be sorted. Different from hashset, treeset is ordered. It is implemented through sortedmap.
Set Summary: 1. set is implemented based on map (hashmap); 2. the elements in the set cannot be repeated. If you use the add (Object OBJ) method to add an existing object, the existing object will be overwritten, it cannot contain two elements, E1 and E2 (e1.equals (E2 )).
Map is a container that associates key objects and value objects. MAP has two common implementations: hashtable, hashmap, and treemap.
Hashmap also uses the hash algorithm to quickly find a key,
Treemap stores keys in sequence, so it has some extension methods, such as firstkey () and lastkey.
The difference between hashmap and hashtable. Hashmap allows null keys or values. The efficiency may be higher than that of hashtable due to non-thread security. Hashtable does not allow null keys or values ).
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.