First, MAP
1. Map and HashMap
Map is an interface, HashMap is an implementation class of map, so it can be defined as follows:
Map<string, integer> m = new hashmap<string, integer> (); Hashmap<string, integer> m = new hashmap<string, integer> ();
cannot be defined as follows, because an interface cannot be instantiated:
Map<string, integer> m = new map<string, integer> (); Hashmap<string, integer> m = new map<string, integer> ();
2. The traversal of map can be referred to:
4 ways to traverse a map object in Java
Second, List
1. List and ArrayList
List is an interface, ArrayList is an implementation class for the list, so it can be defined as follows:
list<string> m = new arraylist<string> (); arraylist<string> m = new arraylist<string> ();
2. The merge of list can be used AddAll function.
3. List to go heavy.
(1), do not care about the order.
public static list removeduplicate (List list) {Set set = new HashSet (); List newlist = new ArrayList (); Set.addall (list); Newlist.addall (set); return newlist;}
(2), hold Order (code from: Java ArrayList to duplicate values)
public static list Removeduplicatewithorder (List list) {Set set = new HashSet (); List NewList = new ArrayList (); for (Iterator iter = List.iterator (); Iter.hasnext ();) {Object element = Iter.next (); if (Set.add (Element)) Newlist.add (element);} return newlist;}
4. The ordering of the custom objects in the list is available for reference:
Common methods and custom methods for Collections.sort () in Java to implement list ordering
Walker * * *
This article is from "Walker's Journal" blog, please be sure to keep this source http://walkerqt.blog.51cto.com/1310630/1688316
About Java's map/list