Example usage for java.util Collections max

List of usage examples for java.util Collections max

Introduction

In this page you can find the example usage for java.util Collections max.

Prototype

public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) 

Source Link

Document

Returns the maximum element of the given collection, according to the natural ordering of its elements.

Usage

From source file:Main.java

public static void main(String[] args) {
    Integer[] numbers = { 8, 2, 6, 7, 0, 1, 4, 9, 5, 3 };

    int min = (int) Collections.min(Arrays.asList(numbers));
    int max = (int) Collections.max(Arrays.asList(numbers));

    System.out.println("Min number: " + min);
    System.out.println("Max number: " + max);
}

From source file:Main.java

public static void main(String args[]) {
    String str[] = { "B", "H", "L", "M", "R" };
    List list = Arrays.asList(str);
    System.out.println(Collections.min(list));
    System.out.println(Collections.max(list));
    Comparator comp = Collections.reverseOrder();
    System.out.println(Collections.min(list, comp));
    System.out.println(Collections.max(list, comp));
}

From source file:Main.java

public static void main(String[] args) {

    Vector<Double> v = new Vector<Double>();

    v.add(new Double("3.4324"));
    v.add(new Double("3.3532"));
    v.add(new Double("3.342"));
    v.add(new Double("3.349"));
    v.add(new Double("2.3"));

    Object obj = Collections.max(v);
    System.out.println(obj);//from w  ww  .  ja va2s . c  o  m
}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-1);/*from w  w w.j  ava  2  s  .  c  o m*/
    list.add(4);
    list.add(-5);
    list.add(1);

    System.out.println("Max value is: " + Collections.max(list));
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<Long> hashSet = new HashSet<Long>();
    hashSet.add(new Long("1111111111"));
    hashSet.add(new Long("2222222222"));
    hashSet.add(new Long("3333333333"));
    hashSet.add(new Long("4444444444"));
    hashSet.add(new Long("5555555555"));

    Object obj = Collections.max(hashSet);
    System.out.println(obj);//from  w ww . ja v a2 s .  c om
}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<Integer> arrayList = new ArrayList<Integer>();

    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("1"));
    arrayList.add(new Integer("8"));
    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("5"));

    Object obj = Collections.max(arrayList);
    System.out.println(obj);//from   w  ww  . j  a  va2  s.  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<Long> hashSet = new HashSet<Long>();
    hashSet.add(new Long("1111111111"));
    hashSet.add(new Long("2222222222"));
    hashSet.add(new Long("3333333333"));
    hashSet.add(new Long("4444444444"));
    hashSet.add(new Long("5555555555"));

    Object obj = Collections.max(hashSet);
    //Object obj = Collections.min(hashSet);
    System.out.println(obj);//w  w w .j a  va 2 s  .  c om
}

From source file:Main.java

public static void main(String args[]) {
    // create link list object 
    List<Integer> list = new LinkedList<Integer>();

    // populate the list  
    list.add(-8);// w ww.ja v a 2 s.  com
    list.add(4);
    list.add(-5);
    list.add(2);

    // comparing using natural ordering
    System.out.println("Max val: " + Collections.max(list));
    System.out.println("Max val: " + Collections.max(list, Collections.reverseOrder()));
}

From source file:Main.java

public static void main(String[] args) {

    for (Character c : LINE.toCharArray()) {

        Integer count = map.get(c);
        map.put(c, count != null ? count + 1 : 0);
    }/*  ww  w .j  a  v  a  2s  .c  om*/
    System.out.println(Collections.max(map.values()));
}

From source file:MainClass.java

public static void main(String[] args) {
    String[] coins = { "Penny", "nickel", "dime", "Quarter", "dollar" };

    Set set = new TreeSet();
    for (int i = 0; i < coins.length; i++)
        set.add(coins[i]);//from   w w  w . j a  va  2 s  .  c o  m

    System.out.println(Collections.min(set));
    System.out.println(Collections.min(set, String.CASE_INSENSITIVE_ORDER));

    System.out.println("");

    System.out.println(Collections.max(set));
    System.out.println(Collections.max(set, String.CASE_INSENSITIVE_ORDER));
}