comparators
play

Comparators Ryan Reid, Megan Lusk, Brian McClintock Sorting - PowerPoint PPT Presentation

Comparators Ryan Reid, Megan Lusk, Brian McClintock Sorting Arrays.sort(anArray) What if you dont want the default sort? Comparators What is a comparator? An Object that implements the Comparator Interface. A Comparator


  1. Comparators Ryan Reid, Megan Lusk, Brian McClintock

  2. Sorting • Arrays.sort(anArray) • What if you don’t want the default sort?

  3. Comparators • What is a comparator? • An Object that implements the Comparator Interface. • A Comparator must use the compare function which takes more than one Object • public int compare(T object, T object) Provides a way to order things that have no natural order.

  4. Uses • Provides a way to order things that don’t have a natural order . • User must create a comparator class to determine how the array will be sorted.

  5. How would you sort a group of vehicles?

  6. Benefits • No longer have to store values • Utilizes polymorphism • Easier to maintain • No need for a compareTo method

  7. Demo

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend