adsense


Showing posts with label JAVA EXAMPLES SEARCH MIN AND MAX. Show all posts
Showing posts with label JAVA EXAMPLES SEARCH MIN AND MAX. Show all posts

Saturday, 24 October 2015

JAVA EXAMPLES SEARCH MIN AND MAX PAGE 49

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES SEARCH MIN AND MAX



Java Examples - Search min and max



Problem Description:
How to search the minimum and the maximum element in an array ?
Solution:
This example shows how to search the minimum and maximum element in an array by using Collection.max() and Collection.min() methods of Collection class .
import java.util.Arrays;
import java.util.Collections;

public class Main {
   public static void main(String[] args) {
      Integer[] numbers = { 8, 2, 7, 1, 4, 9, 5};
      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);
   }
}
Result:
The above code sample will produce the following result.
Min number: 1
Max number: 9