Monday, 25 April 2016

How to find the minimum and maximum number in List or Array ?


To get the minimum or maximum value from the list or array, we can use methods :
  • Collections.min()
  • Collections.max()

Example
Integer[ ] numbers = { 8, 2, 6, 7, 0, 1, 4, 9, 5, 3 };
List list = Arrays.asList(numbers);

int min = (int) Collections.min(list);
int max = (int) Collections.max(list);

No comments:

Post a Comment

Note: only a member of this blog may post a comment.