Bifalgorithm post · Computer science one · Sorted Collections

How does Java sort arrays and lists with comparators?

How does Java sort arrays and lists with comparators? (Computer science one · Sorted Collections) — "As with searching, the Arrays and Collections classes prov…

Ideas in this flowchart

  • Paramétrage du tri des tableaux et des listes en Java
  • Les classes Arrays et Collections fournissent des méthodes de tri paramétrées.
  • Arrays permet de trier des tableaux d’un type particulier avec un Comparator.
  • public static <T> void sort(T[] a, Comparator<T> c)
  • Collections permet de trier des listes avec un Comparator.
  • public static <T> void sort(List<T> list, Comparator<T> c)
  • L’implémentation du tri a évolué selon les versions de Java.
  • Dans Java 6 et les versions antérieures, le tri utilisait une combinaison du tri par fusion et du tri par insertion.
  • Depuis Java 7, l’implémentation utilise Tim Sort.
  • Les méthodes proposent plusieurs variantes fondées sur l’ordre naturel ou limitées à une sous-partie de la collection.
  • Des exemples d’utilisation sont présentés dans Code Sample.
Feed/

How does Java sort arrays and lists with comparators?

No cover

Channel

Computer science one

1 page

"As with searching, the Arrays and Collections classes provide parameterized sorting methods to sort arrays and Lists. In Java 6 and prior, the implementation was a hybrid merge/insertion sort. Java 7 switched the implementation to Tim Sort. Here too, there are several variations that rely on the natural ordering or allow you to sort a subpart of the collection. The Arrays provides the following method, which sorts arrays of a particular type with a Comparator for that type.\n\npublic static <T> void sort(T[] a, Comparator<T> c)\n\nLikewise, Collections provides the following method.\n\npublic static <T> void sort(List<T> list, Comparator<T> c)\n\nSeveral examples of the usage of these methods are presented in Code Sample"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.