Common attributes of Map:
Let’s start with the javaAPI’s description of a MapClick on the image to see hd
To learn more, click on the Java Chinese API download address——————
Understand map features
Unordered LinkedHashMap: unique key, not unique value (order of addition) TreeMap: unique key, not unique value (natural order)Copy the code
Find value by key Return NULL if key does not exist
Map common methods
To learn more, click on the Java Chinese API download address——————
Put (Object obj2,Object obj1) Add an element GET (key) Get the element key is not subscript size() The size of the map set keySet() All the keys of the map set Values () All the values of the map set EntrySet () All keys and values of the map collectionCopy the code
Use map to store country names
Public class TestMap {public static void main(String[] args) {// Create map set // map <String,String> map = new HashMap<String,String>(); //Map<String,String> map = new LinkedHashMap<String,String>(); Map<String,String> map = new TreeMap<String,String>(); Put ("cn", "Chinese"); // Add keys and values to the map set. map.put("us", "America"); map.put("en", "England"); map.put("jp", "Japan"); map.put("us", "the united stas"); map.put("uk", "Japan"); map.put("cs", "cs"); String value = map.get("cs"); System.out.println(value); System.out.println(map.size()); System.out.println(map.keyset ()); System.out.println(map.values()); System.out.println(map); // Print all values system.out.println (map); // Print all key-value pairs. System.out.println(map.entrySet()); // Print all key-value pairs. }}Copy the code
Print the result
Share with you
I want to work my way up
Fly forward on the blades at the highest point
Let the wind blow dry tears and sweat
I want to work my way up
Waiting for the sun to watch its face
Little days have big dreams
I have my day
Let the wind blow dry tears and sweat
One day I will have my day