collections counter sort by value
>>> Counter('abracadabra').most_common(3)
[('a', 5), ('r', 2), ('b', 2)]
collections counter sort by value
>>> Counter('abracadabra').most_common(3)
[('a', 5), ('r', 2), ('b', 2)]
how to sort a collection
List<CustomObject> list = new ArrayList<CustomObject>();
Comparator<CustomObject> comparator = new Comparator<CustomObject>() {
@Override
public int compare(CustomObject left, CustomObject right) {
return left.getId() - right.getId(); // use your logic
}
};
Collections.sort(list, comparator); // use the comparator as much as u want
System.out.println(list);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us