This commit is contained in:
xiangwbs
2018-03-08 19:29:04 +08:00
parent 9269d2abf9
commit 1f32922be2
2 changed files with 1 additions and 19 deletions
@@ -33,7 +33,7 @@ public class LambdaDemo {
List<Integer> lists = Arrays.asList(1, 2, 4, 2, 3, 5, 5, 6, 8, 9, 7, 10);
// //遍历
// Arrays.stream(arrays).forEach(System.out::println);
list.forEach(System.out::println);
list.forEach(System.out::println);//遍历时:对象,json等引用类型可直接转换
lists.sort(Comparator.comparingInt(o -> o));//升序排序,不需要收集
System.out.println("sort:" + lists.stream().sorted((o1, o2) -> o2 - o1).collect(Collectors.toList()));//排序
System.out.println("map:" + lists.stream().map(o1 -> o1 * 2).collect(Collectors.toList()));//转换成新元素
@@ -1,11 +1,5 @@
package com.xwbing.demo;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 项目名称: boot-module-demo
* 创建时间: 2018/1/23 14:45
@@ -14,18 +8,6 @@ import java.util.stream.Collectors;
*/
public class demo {
public static void main(String[] args) {
List<JSONObject> list = new ArrayList<>();
for (int i = 0; i <2 ; i++) {
JSONObject jsonObject=new JSONObject();
jsonObject.put("a","a");
jsonObject.put("b","b");
jsonObject.put("c","c");
list.add(jsonObject);
}
List<String> a1 = list.stream().map(jsonObject ->
jsonObject.getString("a")
).collect(Collectors.toList());
System.out.println(a1);
}