Lab05

5th lab at 14.10.2024

Comparable / Comparator interfaces

Work with Comparable and Comparator

Use project at https://gitlab.vsb.cz/jez04-vyuka/java-efrei/efrei-lab04.git as a base to complete the following tasks.

  1. Crate or use collection of fighters and shuffle them before fighting.
  2. Try to sort collection fithout any change of code.
  3. Ensure that Fighter implements interface Comparable to compare fighters baso on name.
  4. Try to sort collection again.
  5. Mesure time of searching an object in unsorted collection a using binarySearch in sorted collection.
  6.  Use interface Comparator to compare Fighters base on strenght.
  7. Find the most strongest and the most weekest  Fighter in unsorted collection.
  8. Create comparator which compare Fighters base on name and if name are same compare them base on strenght.
  9. Use static methods in class comparator to create comparator which handle null values
  10. Use static methods in class comparator to create comparator which use keyExtractor to compare fighters base on remaining lives.
  11. Try to compare collection of strings  witch contains language specific character like ('č', 'ř', 'Ž'). Try to use class  Collator. Get the instance using method Collator.getInstance
  12. Try to create comparator which compare string with numbers (like street name with number in post address). String format could be "street_name 1234". Comparator compare first part of string and if it same compare second part as number so "street 19" will be greater then "street 8".

Solution

solution can be found in project original project in branche solution