HashMap and Linkedhashmap are two implementation classes of the map interface, the biggest difference is that hashmap elements are stored in order, and the elements of Linkedhashmap are stored in an orderly manner, example:
map<string, integer> hashMap = new hashmap<string, integer> (); map<string, integer> linkedhashmap = new linkedhashmap<string, integer> (); for (int i = 0; i <; i++) {have Hmap.put (String.valueof (i), i), Linkedhashmap.put (string.valueof (i), i); System.out.println ("HashMap"); for (entry<string, integer> entry:hashMap.entrySet ()) {System.out.println ( Entry.getkey () + ":" + entry.getvalue ());} System.out.println ("Linkedhashmap"); for (entry<string, integer> entry:linkedHashMap.entrySet ()) { System.out.println (Entry.getkey () + ":" + entry.getvalue ());
Output Result:
Hashmap3:32:21:10:07:76:65:54:49:98:8linkedhashmap0:01:12:23:34:45:56:67:78:89:9
Previously also published a book to achieve the order of the map elements "Java implementation map set sorting function", did not expect to be their own shot bricks, now think of no culture can be really scary ah ...
The difference between Java HashMap and Linkedhashmap