![](/img/trans.png)
[英]Using Java 8, what is the most preferred and concise way of printing all the lines in a file?
[英]Using Java 8, what is the most concise way of iterating through all the entries in a map?
使用新的Java 8迭代Map中所有條目的最簡單方法是什么?
我認為這是迭代Map中所有條目的最簡潔,最簡單的方法:
創建地圖:
Map map = new HashMap() {{
put("key1", "value1");
put("key2", "value2");
}};
瀏覽所有鍵和值:
map.forEach( (k, v) -> System.out.println("key: " + k + " value: " + v) );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.