undefined

Practice with sorting and using Comparator

Java Multithreading
Level 6 , Lesson 2
Available

"Hi, Amigo!"

undefined
28
Task
Java Multithreading, level 6, lesson 2
Locked
Read online about the median of a sample
Implement the logic of the sort() method. It must sort the data in the array according to its distance from the median. Return the array sorted from the least to greatest distance. If several numbers are equally distant, then sort them in ascending order.
undefined
8
Task
Java Multithreading, level 6, lesson 2
Locked
Think and you will succeed
Soldiers have always assembled, do assemble, and will assemble by descending height. After thinking about whether it would be better to use Comparable or Comparator for this task, sort the soldiers.
undefined
14
Task
Java Multithreading, level 6, lesson 2
Locked
A convert can easily convert others
A table has columns that can be sorted. The user can customize the list of columns that will be sorted. Write a public static Comparator CustomizedComparator that will: 1. take an array of comparators via the constructor. 2. sort data in the order that corresponds to the sequence of comparators.
Comments (3)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Maria Level  34, Utrecht, Netherlands
1 November 2020
If a class has obvious natural sorting logic (0-10, a - z), then it is better to use Comparable, in other cases Comparator
Ewerton Level  30, Belo Horizonte, Brasil
13 July 2019
- "Think about which is best to use, and then implement Comparable or Comparator". - Ok, I wrote a one-line solution using comparator. - WRONG, "Be sure that the Soldier class implements the Comparable interface". ...