finding 19th largest number from array in java code example
Example 1: java how to find the largest number in an arraylist
List<Integer> myList = new ArrayList<>();
for(int i = 0; i < 10; i++){
myList.add(i);
}
int highestNumber = Collections.max(myList);
System.out.Println(highestNumber);
Example 2: find the maximum number from an int Array
---without sort method---
public static int maxValue( int[] n ) {
int max = Integer.MIN_VALUE;
for(int each: n)
if(each > max)
max = each;
return max;
---with sort method---
public static int maxValue( int[] n ) {
Arrays.sort( n );
return n [ n.lenth-1 ];
}
Example 3: java find largest number in list
int max = (The provided List).stream().max((i1,i2)->(i1>i2)?1:(i1<i2)-1:0).get();