lambda表達式實例

//合併2個集合 及添加過濾條件   來源java8 in action
List<Integer> numbers1 =  Arrays.asList(1,2,3);
		List<Integer> numbers2 =  Arrays.asList(3,4);
		List<int[]> pairs = numbers1.stream().flatMap(i -> numbers2.stream().filter(k -> (k+i)%3 == 0).map(j -> new int[]{i,j})).collect(Collectors.toList());
		pairs.forEach(k -> System.out.println(k[0]+","+k[1]));
//合併map value 的list
Map<String,List<SnTestResultProject>> reportData = new HashMap();
reportData.values().stream().flatMap(k->k.stream()).collect(ArrayList::new, List::add, List::addAll)
相關文章
相關標籤/搜索