小弟程式菜鸡,最近想考OCPJP
关于一些考古题
List<Student> stds = Arrays.asList(
new Student("Jessy", "Java ME", "Chicago"),
new Student("Helen", "Java EE", "Houston"),
new Student("Mark", "Java ME", "Chicago"));
stds.stream().collect(Collectors.groupingBy(Student::getCourse))
.forEach((src, res) -> System.out.println(res));
这时候不管new Student建立的顺序怎么换
都会显示
Java EE
Java ME
但是换成
List<Country> couList = Arrays.asList(
new Country("Japan", Country.Continent.ASIA),
new Country("Italy", Country.Continent.EUROPE),
new Country("Germany", Country.Continent.EUROPE));
Map<Country.Continent, List<String>> regionNames =
couList.stream().
collect(Collectors.groupingBy(Country::getRegion
,Collectors.mapping(Country::getName,
Collectors.toList())));
System.out.println(regionNames);
此时显示
EUROPE在前
ASIA在后
我自己测试是发现排列的顺序变成先建立的放后面
所以该怎么判断这时候是使用怎样排序的?
请各位高手帮我解惑QQ