在Java 8中可以通过下面的方式获取Map对象的第一个元素:
1.获取元素键
//if order is important, e.g. with a TreeMap/LinkedHashMap
map.keySet().stream().findFirst();
//if order is not important or with unordered maps (HashMap...)
map.keySet().stream().findAny();
2.获取元素键值
//if order is important, e.g. with a TreeMap/LinkedHashMap
map.values().stream().findFirst();
//if order is not important or with unordered maps (HashMap...)
map.values().stream().findAny();
3.获取元素
//if order is important, e.g. with a TreeMap/LinkedHashMap
map.entrySet().stream().findFirst();
//if order is not important or with unordered maps (HashMap...)
map.entrySet().stream().findAny();
References
最新评论
大佬用了魔法还是用不了,无互联网访问
地址挂了
如果不用魔法是不是下载了也看不了
请问大佬能推荐渠道么 十分感恩