|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.function.BiConsumer; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.function.Predicate; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -14,15 +15,27 @@ import java.util.stream.Collectors; |
|
|
|
public class StreamDemo { |
|
|
|
public static void main(String[] args) { |
|
|
|
List<DataEntity> list = extracted(100); |
|
|
|
//1.字段汇总
|
|
|
|
Set<String> collect = list.stream() |
|
|
|
.map(DataEntity::getName).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
for (DataEntity entity : list) { |
|
|
|
String classNo = entity.getClassNo(); |
|
|
|
} |
|
|
|
//1.字段汇总 a->a.getName() DataEntity::getName
|
|
|
|
Set<Object> collect = list.stream() |
|
|
|
.map(new Function<DataEntity, Object>() { |
|
|
|
@Override |
|
|
|
public Object apply(DataEntity dataEntity) { |
|
|
|
return dataEntity.getName(); |
|
|
|
} |
|
|
|
}).collect(Collectors.toSet()); |
|
|
|
//2.条件过滤
|
|
|
|
List<DataEntity> collect1 = list.stream().filter(dataEntity -> dataEntity.getClassNo().equals("NO.3")).collect(Collectors.toList()); |
|
|
|
//3.分组
|
|
|
|
Map<String, List<DataEntity>> map = list.stream().collect(Collectors.groupingBy(dataEntity -> dataEntity.getClassNo())); |
|
|
|
//4.转换
|
|
|
|
//list;->point_code = '001'
|
|
|
|
Map<String, DataEntity> map2 = list.stream().collect(HashMap::new, (k, v) -> k.put(v.getName(), v), HashMap::putAll); |
|
|
|
DataEntity dataEntity = map2.get("e4563a6b-94c1-4817-97aa-d66a8b21640f"); |
|
|
|
System.out.println(dataEntity.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|