Bifalgorithm post · Computer science one · Searching

How can a Comparator sort Student objects by GPA?

How can a Comparator sort Student objects by GPA? (Computer science one · Searching) — "Comparator byGpa = new Comparator () {\n\n@Override\n\npublic int compa…

Ideas in this flowchart

  • Les méthodes de recherche et de tri du JDK prennent en charge différents ordres de classement.
  • La plupart de ces méthodes sont des implémentations génériques.
  • Elles peuvent trier des tableaux.
  • Elles peuvent trier des collections.
  • Elles peuvent utiliser l'ordre naturel des éléments.
  • Elles peuvent recevoir un Comparator<T> paramétré pour définir l'ordre.
  • L'exemple crée un Comparator<Student> fondé sur le GPA.
  • La méthode compare reçoit deux objets Student.
  • b.getGpa().compareTo(a.getGpa()) place les GPA les plus élevés avant les plus faibles.
Feed/

How can a Comparator sort Student objects by GPA?

No cover

Channel

Computer science one

1 page

"Comparator<Student> byGpa = new Comparator<Student>() {\n\n@Override\n\npublic int compare(Student a, Student b) {\n\nreturn b.getGpa().compareTo(a.getGpa());\n\n}\n\n};\n\nWe now turn our attention to the search and sorting methods provided by the JDK. Most of these methods are generic implementations that either sort an array or collection using the natural ordering or take a parameterized Comparator<T> to determine the ordering."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.