在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

i软糖


最新评论
宝藏网站,差点找不回来了,之前我收藏的发布页打不开了。。。
谢谢您可以
视频资源很全好用,安装后提示更新,安装包站长可以更新一下。
哪个国家成功率高一点?换了十几个了