identify highest value java program code example

Example 1: 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 2: how to find the largest integer in java

int a = Integer.MAX_VALUE;

Example 3: find highest value in keyset java

countMap.entrySet().stream().max((entry1, entry2) -> entry1.getValue() > entry2.getValue() ? 1 : -1).get().getKey();

Tags:

Misc Example