Do you know you can earn heaps of $$ by answering questions on kodlogs, for more info contact us through feedback link at footer? We are Australian based web site and pay you for answering questions

  • Register
Welcome to Kodlogs Q&A, where you can ask programming questions and receive answers from other members of the community. For programmers, by programmers Kodlogs is an open community for anyone that does coding. We help you get answers to your toughest coding questions, share knowledge with your coworkers in private, and find your next IT dream job.
0 votes
How to use Collections.sort java ? how to use collections.sort on arraylist? Is there collection.sort comparator?

How do you sort collections?

How do you use collections sort in ArrayList?

How do I sort a collection order in reverse?

Which algorithm is used in collections sort method?
by (8.8k points)  
edited by

4 Answers

0 votes
java.util.Collections.sort() technique is available in java.util.Collections class.


Class Collections



Java Collections class furnishes us with an extremely advantageous technique Collections.sort() to sort all List executions, for example, LinkedList and ArrayList.

Accumulations class gives static techniques to arranging the components of a gathering. On the off chance that gathering components are of a Set kind, we can utilize TreeSet.

Following is the affirmation for java.util.Collections.sort() strategy.

open static <T broadens Comparable<? super T>> void sort(List<T> list)
by (8.8k points)  
0 votes

Collections.sort() methods are as following:

  1. sort(List list)
  2. sort(List list, Comparator c)
by (8.8k points)  
0 votes


private void CollectionToSort(List<String> wordsList) {
 Map<Integer, Set<String>> mapping = new HashMap<>();
 for (String word : wordsList) {
  mapping.computeIfAbsent(word.length(), HashSet::new).add(word);
 List<Integer> lengths = new LinkedList<>(mapping.keySet());
 lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars"));
by (8.8k points)  
0 votes
by (8.8k points)