Class ListUtils

java.lang.Object
it.unimi.di.prog2.h23.ListUtils

public class ListUtils extends Object
A class providing some utility methods for lists.
  • Constructor Details

    • ListUtils

      private ListUtils()
      .
  • Method Details

    • almostRightMax

      public static <T extends Comparable<T>> T almostRightMax(List<T> lst)
      Returns the maximum element in a list.

      This implementation has an issue with subclasses.

      Type Parameters:
      T - the type of the elements in the list.
      Parameters:
      lst - the list.
      Returns:
      the maximum element in lst.
      Throws:
      NullPointerException - if lst is null.
    • max

      public static <T extends Comparable<? super T>> T max(List<T> lst)
      Returns the maximum element in a list.
      Type Parameters:
      T - the type of the elements in the list.
      Parameters:
      lst - the list.
      Returns:
      the maximum element in lst.
      Throws:
      NullPointerException - if lst is null.
    • main

      public static void main(String[] args)
      A method to test the code in this class
      Parameters:
      args - unused.