题解 | #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<Map.Entry<Integer, String>> entrys = map.entrySet();
        for (Map.Entry<Integer, String> entry : entrys) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
map.put(5, name);
map.remove(4);
map.put(3, "Tommy");
 System.out.println(" ");
        Set<Map.Entry<Integer, String>> entrys1 = map.entrySet();
        for (Map.Entry<Integer, String> entry1 : entrys) {
            System.out.println(entry1.getKey() + ":" + entry1.getValue());
        }
    }
}

全部评论

相关推荐

最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
03-19 10:36
云南大学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务