List<User> list = new ArrayList<>();
1、list转Map<String, String>
Map<String, String> resultMap = list.stream().collect(Collectors.toMap(User::getName, User::getOtherName));
2、list转Map<String, Set<String>>
Map<String, Set<String>> resultMap= list.stream().collect(Collectors.groupingBy(e -> e.getCategory() + "_" + e.getVersion(),
Collectors.mapping(User::getName, Collectors.toSet())));
Map<String, List<String>> resultMap= list.stream().collect(Collectors.groupingBy(e -> e.getCategory() + "_" + e.getVersion(),
Collectors.mapping(User::getEventName, Collectors.toList())));
3、list转Map<String, List<User>>
Map<String, List<User>> resultMap = list.stream().collect(Collectors.groupingBy(User::getName));
Map<String, List<Map>> resultMap = list.stream().collect(Collectors.groupingBy(e->e.get("entityName").toString()));
3.1 list 转换字段 以及对应的数量
Map<String, Long> mapProperty = list.stream()
.collect(Collectors.groupingBy(User::getName, Collectors.counting()));
4、list转Map<String, User>
Map<String, User> resultMap = list.stream().collect(Collectors.toMap(i ->
i.getName(), Function.identity(), (k1, k2) -> k2));
5、list转List<String>
List<String> events = list.stream().map(User::getName).collect(Collectors.toList());
去重
List<String> events = list.stream().map(User::getName).distinct().collect(Collectors.toList());
排序
List<String> events = list.stream().map(User::getName).distinct().sorted().collect(Collectors.toList());
6、list转Set<String>
Set<String> events = list.stream().map(e -> e.getName()).collect(Collectors.toSet());
Set<Integer> forecastModelIds = list.stream().map(User::getId).collect(Collectors.toSet());
带排序
Set<String> newData = list.getLabelDetails().stream().map(e -> e.getEventName())
.sorted().collect(Collectors.toCollection(LinkedHashSet::new));
7、对List<User> 中entityCategory进行分组,count进行求和
Map<String, Integer> result = list.stream()
.collect(Collectors.groupingBy(User::getName,
Collectors.summingInt(User::getCount)));
8、对List<User>中字段count求和
Integer total = entityClassyDetail.stream().mapToInt(User::getCount).sum();
9.取id对应最小的日期
Map<Integer, Data> result = dataList.stream()
.collect(Collectors.groupingBy(Data::getId,
Collectors.minBy(Comparator.comparing(Data::getDate))));
10、list去重
List<String> list = List.of("apple", "banana", "apple", "orange", "banana", "pear");
List<String> distinctList = list.stream().distinct().collect(Collectors.toList());
#if($_parameter.labelSecondaryName.contains("-"))
AND ( f.LABEL_SECONDARY_NAME IS NULL
#if($!{_parameter.labelSecondaryName.size()}>1)
OR f.LABEL_SECONDARY_NAME IN (#repeat( $_parameter.labelSecondaryName $item ",") @{item}#end)
#end
)
#end
#if(!$_parameter.labelSecondaryName.contains("-"))
AND f.LABEL_SECONDARY_NAME IN (#repeat( $_parameter.labelSecondaryName $item ",") @{item}#end)
#end
List<String> mips = Collections.singletonList("1");
mips = Arrays.asList("1","2");
excel
字符串拼接
=CONCATENATE("UPDATE tableName SET RULE_NAME='",B49,"' WHERE RULE_NAME='",A49,"';")
=CONCATENATE("('",A2,"','",B2,"','",C2,"','",D2,"','",E2,"','",F2,"','",G2,"','",H2,"','",I2,"','",J2,"'),")
/*+ SET_VAR(query_timeout = 36000)*/
循环map
Map<Integer, List<Object>> forecastMap =
for (Map.Entry<Integer, List<Object>> i : forecastMap.entrySet()) {
}
输出时间
DateUtil.spendMs(start)
-- 查询表字段
SELECT
GROUP_CONCAT(CONCAT('`',COLUMN_NAME,'`'))
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'dbName'
AND TABLE_NAME = 'tableName';
SELECT
GROUP_CONCAT(CONCAT('SUM(`',COLUMN_NAME,'`) ',COLUMN_NAME))
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'dbName'
AND TABLE_NAME = 'tableName';
SELECT
CONCAT(',t.`',COLUMN_NAME,'`=w.',COLUMN_NAME)
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'dbName'
AND TABLE_NAME = 'tableName';