//Map按照value 倒序
LinkedHashMap<Integer, Integer> sortedMap = support_level_map.entrySet().stream()
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue(), (x1, x2) -> x2, LinkedHashMap::new));
//升序
LinkedHashMap<String, BigDecimal> sortedMap = map.entrySet().stream()
.sorted(Map.Entry.comparingByValue())
.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue(), (x1, x2) -> x2, LinkedHashMap::new));
//如果supportLevelMap中存在两个以上value是相等的,就为 不确定
Long maxValue = CalUtil.getMaxValue(supportLevelMap);
List<String> keys = CalUtil.getKeysByStream(supportLevelMap, maxValue);
if(keys.size() > 1){
//因为数据库字段emotion_determine默认就是0
continue;
}
/**
* 求Map<K,V>中Value(值)的最大值
*
* @param map
* @return
*/
public static Long getMaxValue(Map<String, Long> map) {
if (map == null) {
return null;
}
int length =map.size();
Collection<Long> c = map.values();
Object[] obj = c.toArray();
Arrays.sort(obj);
return (Long) obj[length-1];
}
/**
* @description: 根据value获取map中的key
* @return: java.util.Set<K>
* @author: hezha
* @time: 2022/4/16 17:39
*/
public static List<String> getKeysByStream(Map<String, Long> map, Long value) {
return map.entrySet()
.stream()
.filter(kvEntry -> Objects.equals(kvEntry.getValue(), value))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
}
给定字符串,逗号切割,去空格,最后存入List
List<String> collect = Arrays.stream(str.split(",")).collect(Collectors.collectingAndThen(Collectors.toList(),x->x.stream().map(i->i.trim()).collect(Collectors.toList())));