Introduction to Android ArrayList LinkedList Set hashmap.

Source: Internet
Author: User

In Android development we often need to classify and manipulate the data, for the lightweight data storage we may not need to use SQLite or efficiency and class library imperfect XML, because Sharedpreferences does not have the data enumeration method, If just a string or int array can be separated by a single tag, we'll take a look at Android or the Java-provided basic data type helper class ArrayList LinkedList Set HashMap.


The collection and map interfaces are available in Java. The list and set inherit the collection interface, while the vector, ArrayList, linkedlist three classes implement the list interface, HashSet and TreeSet implement the set interface. Directly have Hashtable, HASHMAP, TREEMAP implementation Map interface.

Vector array-based list, the performance is not beyond the array, and the vector is "sychronized", this is the only difference between vector and ArrayList.

ArrayList: Same as Vector is an array-based, but the difference is that ArrayList is not synchronous. So the performance is better than the vector. DevDiv prompts you for sequential lookups

LinkedList: Unlike the previous two lists, it is not based on array, as a linked list data structure, so it is not limited by the array performance. When adding to the LinkedList, deleting the action can only be done by changing the relevant information of the nextnode so it is suitable for frequent insertions and deletions. This is the advantage of LinkedList, of course, the location of the element is not much less.

List:

1. All lists can contain only a single table of different types of objects, not key-value key-value pairs. For example: [Tom,1,c];

2. All lists can have the same elements, such as vector can have [tom,koo,too,koo];

3. All lists can have null elements, for example [tom,null,1];

4. Array-based list (vector,arraylist) is suitable for querying, while LinkedList (linked list) is suitable for adding, deleting operations.

Although both set and list implement the collection interface, they are implemented in a very different way. The list is basically based on an array. But set is implemented on the basis of HashMap, which is the fundamental difference between set and list.

Hashset:hashset Storage method is the HashMap in the key as the corresponding storage of the set, HashMap key can not be duplicated. HashSet can quickly locate an element, but objects placed in hashset need to implement Hashcode () method 0.

TreeSet: The elements placed therein are stored sequentially, which requires that the objects you put into them are sortable. TreeSet is different from the hashset of the fundamental is treeset is orderly. It is achieved through SORTEDMAP.

Set Summary: 1. The base of set implementation is map (HASHMAP); 2. Elements in set cannot be duplicated, and if an existing object is added using the Add (Object obj) method, the previous object is overwritten and cannot contain two elements E1, E2 (E1.equals (E2)).

Map is a container for associating key objects with value objects, and map has two more common implementations: HashTable, HashMap, and TreeMap.

HashMap also uses the hash code algorithm to quickly find a key,

TreeMap is a key-ordered storage, so it has some extended methods, such as Firstkey (), Lastkey () and so on.

The difference between HashMap and Hashtable. HASHMAP allows null (NULL) keys or values (value), which may be more efficient than Hashtable due to non-thread safety. Hashtable does not allow NULL (NULL) keys or values (value).

Introduction to Android ArrayList LinkedList Set hashmap.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.