java program to find second largest number in an array code example

Example 1: second largest value in array java 8

public class ThirdLargestNumberInAnArray {
   public static void main(String args[]){
      int temp, size;
      int array[] = {10, 20, 25, 63, 96, 57};
      size = array.length;

      for(int i = 0; i<size; i++ ){
         for(int j = i+1; j<size; j++){

            if(array[i]>array[j]){
               temp = array[i];
               array[i] = array[j];
               array[j] = temp;
            }
         }
      }
      System.out.println("Third second largest number is:: "+array[size-2]);
   }
}

Example 2: java find largest number in list

int max = (The provided List).stream().max((i1,i2)->(i1>i2)?1:(i1<i2)-1:0).get();

Tags:

Misc Example