Java 比较

From Kiwi
Jump to: navigation, search

Java 比较

List内容比较

List<Map.Entry<Character, Integer>> list = new ArrayList<>();
list.sort(Comparator.comparing(Map.Entry::getValue));

Collections内容比较

List<Map.Entry<Character, Integer>> list = new ArrayList<>();
Collections.sort(Comparator.comparing(Map.Entry::getValue));

Collections内容比较Lambda

List<Map.Entry<Character, Integer>> list = new ArrayList<>();
Collections.sort(list, (o1, o2) -> o1.getValue().compareTo(o2.getValue()));

Collections内容比较 new Comparator

List<Map.Entry<Character, Integer>> list = new ArrayList<>();
Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() {
	@Override
	public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
		return o1.getValue().compareTo(o2.getValue());
	}
});