Generally everyone knows the general difference between ArrayList and LinkedList:
1.ArrayList is the realization of the data structure based on dynamic array, LinkedList data structure based on linked list.
2. For random access get and set,arraylist feel better than LinkedList, because linkedlist to move the pointer.
3. Add and Remove,linedlist are the dominant for new and deleted operations because ArrayList is moving the data.
This point depends on the actual situation. If you insert or delete only a single piece of data, the ArrayList speed is better than LinkedList. But if bulk random insert deletes data, LinkedList speed is much better than ArrayList. Because ArrayList each insertion of data, you move the insertion point and all subsequent data.
4. Find Operation Indexof,lastindexof,contains and so on, both similar.
5. Randomly find the operation of the specified node get,arraylist faster than LinkedList.
Set is the simplest kind of collection. The objects in the collection are not sorted in a particular way, and there are no duplicate objects. The set interface mainly implements two implementation classes:
- The Hashset:hashset class accesses the objects in the collection according to the hashing algorithm, and the access speed is relatively fast.
- The Treeset:treeset class implements the SortedSet interface and is able to sort the objects in the collection.
Set usage: Holds reference to object, no duplicate object
A list is characterized by its elements being stored in a linear fashion, in which duplicate objects can be stored in the collection.
The main implementation classes of the list interface are:
- ArrayList (): Represents the length can be changed by the group. Elements can be randomly accessed, and it is slow to insert and delete elements into ArrayList ().
- LinkedList (): A linked list data structure is used in the implementation. Fast insertion and deletion, and slow access times.
For random access to a list, it is just random to retrieve the element at a particular location. The Get (int index) method of the List returns the object in the collection at the index location specified by the parameter index, starting with "0". The two most basic ways to retrieve all objects in a collection are:
Advantages and disadvantages of several data structures in Java