The value of map in java

package com.itcast.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.junit.Test;

public class MapTest {

/* *
* Two ways to get the value in Map
*/
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("zhangsan", 20);
map.put("lisi", 21);
map.put("wangwu", 25);
Set<String> set = map.keySet();// Get the set of keys inside
for (String str : set) {// Traverse the set to get the key inside
System.out.println(map.get(str) + " ");// Through the key, get the value and print it out

}
}

@Test
public void getvalue() {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("wuyihua", 20);
map.put("kexiwang", 21);
map.put( "luxiaohu", 25);
Set<Entry<String, Integer>> set = map.entrySet();// Get the object set set of key-value pairs
for (Entry<String, Integer> en : set) {// Traverse A collection of key-value pairs
System.out.println(en.getValue() + " ");// Get the value inside through the key-value pair object
}
}
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326722545&siteId=291194637