java8-lambda之集合測試

@Test
public void testMapLambda() {

    Map<String, Object> map = new ConcurrentHashMap<>();
    map.put("A", 10);
    map.put("B", 20);
    map.put("C", 30);
    map.put("D", 40);
    map.put("E", 50);
    map.put("F", 60);

    List<String> arraylist = new CopyOnWriteArrayList<>();
    map.forEach((key, value) -> {
        arraylist.add(key);
        map.remove(key);
    });

    arraylist.stream().filter(key-> key.contains("B") || key.contains("C")).forEach(key->{
        arraylist.add(key);
    });
    arraylist.forEach(v->{
        System.out.println(v);
    });
}
相關文章
相關標籤/搜索