标签:list entryset rev tag 转换 static stream tor pst
定义字符串数组 String[] strArr
String[] strArr = {"Red", "Green", "Blue"};
List<String> list = Arrays.asList(strArr);
String[] strArrNew = list.toArray(new String[0]);
String str = String.join(",", list);
List<String> list2 = new ArrayList<>(Arrays.asList(str.split(",")));
定义对象 Person
private static class Person {
private String name;
private Integer age;
}
定义对象 Person 的集合 List
List<Person> personList = Lists.newArrayList(
new Person("Jordan", 38),
new Person("O'Neal", 34),
new Person("James", 31),
new Person("Kobe", 34),
new Person("Trace", 32)
);
对象集合转为 Map
Map<String, Integer> personMap = personList.stream().collect(Collectors.toMap(Person::getName, Person::getAge));
list.sort(Comparator.naturalOrder());
personList.sort(Comparator.comparing(Person::getAge).reversed());
personMap.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (o, n) -> o, LinkedHashMap::new));
标签:list entryset rev tag 转换 static stream tor pst
原文地址:https://www.cnblogs.com/bigshark/p/11370958.html