Home »
Java programming language
Java Calendar getMaximum() Method with Example
Calendar Class getMaximum() method: Here, we are going to learn about the getMaximum() method of Calendar Class with its syntax and example.
Submitted by Preeti Jain, on February 01, 2020
Calendar Class getMaximum() method
- getMaximum() method is available in java.util package.
- getMaximum() method is used to get the highest value of the given field (fi) of this Calendar.
- getMaximum() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
- getMaximum() method does not throw an exception at the time of returning the maximum value.
Syntax:
public abstract int getMaximum(int fi);;
Parameter(s):
- int fi – represents the field(fi) of this Calendar.
Return value:
The return type of the method is int, it returns the maximum value of the given calendar field.
Example:
// Java Program to demonstrate the example of
// int getMaximum(int fi) method of Calendar
import java.util.*;
public class GetMaximum {
public static void main(String args[]) {
// Instantiating a Calendar object
Calendar ca = Calendar.getInstance();
// Display current calendar
System.out.println("ca: " + ca.getTime());
// By using getMaximum(int fi) method is
// to return the maximum value of the given field
int month = ca.getMaximum(Calendar.MONTH);
//Display maximum value of month
System.out.println("ca.getMaximum(Calendar.MONTH): " + month);
}
}
Output
ca: Mon Jan 27 07:39:35 GMT 2020
ca.getMaximum(Calendar.MONTH): 11