题解 | #map简单应用#
map简单应用
https://www.nowcoder.com/practice/7a47e465315c40848d5daba676f9ac29
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String name = scanner.next(); Map<Integer, String> map = new HashMap<Integer, String>(); map.put(1, "Amy"); map.put(2, "Joe"); map.put(3, "Tom"); map.put(4, "Susan"); //write your code here...... Set<Integer> keyset1 = map.keySet(); for(int k : keyset1){ String v = map.get(k); System.out.println(k +":"+v); } map.put(5, name); map.put(3, "Tommy"); map.remove(4); System.out.println(); // 空行隔开 Set<Integer> keyset2 = map.keySet(); for(int k : keyset2){ String v = map.get(k); System.out.println(k +":"+v); } } }