The collection operation is carried out in a simple test speed, the data volume is 20w, and the map,list,set,array,queue is compared with the Traverse test time.
Paste an Introduction to these collections first:
1.1 Set Interface
- Each element that is stored in the set must be unique, and the set interface does not guarantee the order of the elements being maintained;
- HashSet class: In order to quickly find the set of the design, the object stored in HashSet must define HASHCODE (), which does not guarantee the iteration order of the set;
- Linkedhashset class: Has a hashset query speed, and internally uses the chain list to maintain the order of elements (the Order of insertions).
1.2 List interface
- The list saves objects in the order in which they are entered, and does not perform operations such as sorting;
- ArrayList class: A list implemented by an array that allows fast random access to elements, but inserts and removes elements from the list is slow;
- LinkedList class: Sequential access is optimized, and the cost of inserting and deleting to the list is small, and random access is relatively slow.
1.3 Queue Interface
- The queue is used to simulate the data structure of queues such as "FIFO". Typically, queues do not allow random access to elements in the queue.
- Arraydeque Class: The implementation class for the queue sub-interface deque, array way.
- LinkedList class: Is the implementation class of the list interface, and it also implements the Deque interface (queue sub-interface). So it can also be used as a double-ended queue, or as a "stack".
1.4 Map Interface
- Add, remove Operations Put/remove/putall/clear
- Query Operation Get/containskey/containsvalue/size/isempty
- View Operation Keyset/values/entryset
- The Map.entry interface (map's EntrySet () method returns a collection of objects that implement the Map.entry interface) Getkey/getvalue/setvalue
Here is the test code:
public static int leng = 200000;private string[] array;private set<string> set;private list<string> List;priv Ate queue<string> queue;private map<string, string> Map; @Beforepublic void init () {array = new String[leng];s ET = new hashset<string> (); list = new arraylist<string> (); queue = new linkedlist<string> (); map = new has Hmap<string, string> (); for (int i = 0; i < Leng; i++) {String key = "Didi:" + i; String value = "Da"; array[i] = Key;set.add (key); List.add (key); Queue.add (key); Map.put (key, value);}} shzu@testpublic void Testarray () {Long startTime = new Date (). GetTime (); for (String Sk:array) {///}long endTime = new Date (). GetTime (); Long times = endtime-starttime; System.out.println ("Time:" + times);} list@testpublic void Testlist () {Long startTime = new Date (). GetTime (); for (String sk:list) {///}long endTime = new D Ate (). GetTime (); Long times = endtime-starttime; System.out.println ("Time:" + times);} map@testpublic void TestMap () {Long startTime = new Date (). GetTime (); for (map.entry<string, string> entry:map.entrySet ()) {Entry.getkey ();} Long endTime = new Date (). GetTime (); Long times = endtime-starttime; System.out.println ("Time:" + times); Long startTime1 = new Date (). GetTime (); for (string Key:map.keySet ()) {String value = (String) map.get (key);} Long endTime1 = new Date (). GetTime (); Long times1 = endtime-starttime; System.out.println ("Time 1:" + times1);} queue@testpublic void Testqueue () {Long startTime = new Date (). GetTime (); for (String s:queue) {//}long endTime = new D Ate (). GetTime (); Long times = endtime-starttime; System.out.println ("Time 1:" + times);} set@testpublic void Testset () {Long startTime = new Date (). GetTime (); for (String s:set) {//}long endTime = new Date (). GetTime (); Long times = endtime-starttime; System.out.println ("Time:" + times);}
Time: Array:4ms,list:17ms,map:14ms,13ms,queue:15ms,set:14ms
Data based on each test a slight gap, but the difference is not small, array and other differences the largest, belong to the fastest traversal, list slowest.
Reference: http://www.cnblogs.com/nayitian/archive/2013/03/08/2950730.html
Several operating speed comparisons