How to find min and max in ArrayList of integers with Java

1 Answer

0 votes
import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        ArrayList<Integer> al = new ArrayList<Integer>(Arrays.asList(5, 2, 9, 7, 1, 3, 4)); 
  
        int min = Collections.min(al);
        int max = Collections.max(al);

        System.out.println(min);
        System.out.println(max);
    }
}



/*
run:

1
9

*/

 



answered Sep 6, 2020 by avibootz

Related questions

2 answers 112 views
1 answer 137 views
1 answer 77 views
1 answer 223 views
1 answer 166 views
...