The max() method returns greater of two int numbers passed as arguments to this method. It works similar to Math.max() method.
Hierarchy:
java.lang Package
-> Integer Class
-> max() Method
Syntax of max() method
public static int max(int a, int b)
max() Parameters
a– An int number passed as first argument to max method.b– An int number passed as second argument to max method.
max() Return Value
- The greater number between arguments
aandb.
Supported versions: Java 1.8 and onwards.
Example 1
public class JavaExample {
public static void main(String[] args) {
int a = 10, b = 20;
System.out.println("Greater of a and b: "+Integer.max(a,b));
}
}
Output:

Example 2
public class JavaExample {
public static void main(String[] args) {
int a = -10, b = -20;
System.out.println("Given integers are: "+a+", "+b);
System.out.println("Greater of given negative integers: "+
Integer.max(a,b));
}
}
Output:

Example 3
public class JavaExample {
public static void main(String[] args) {
int a = -1001, b = Integer.MIN_VALUE;
System.out.println("Given integers are: "+a+", "+b);
System.out.println("Greater of these two numbers: "+
Integer.max(a,b));
}
}
Output:
