- Arrays.sort();自定义排序规则
Arrays.sort(people, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[0] != o2[0]) {
return o1[0] - o2[0];
}else {
return o2[1] - o1[1];
}
}
});
Arrays.sort(str, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
String str1 = o1+o2;
String str2 = o2+o1;
return str2.compareTo(str1);
}
});
- map遍历
Map <String,String>map = new HashMap<String,String>();
map.put("四川", "成都");
map.put("吉林", "长春");
for(Map.Entry<String, String> entry : map.entrySet()){
String mapKey = entry.getKey();
String mapValue = entry.getValue();
System.out.println(mapKey+":"+mapValue);
}
for(String key : map.keySet()){
System.out.println(key);
}
for(String value : map.values()){
System.out.println(value);
}