Home »
Java programming language
Java GregorianCalendar getMaximum() Method with Example
GregorianCalendar Class getMaximum() method: Here, we are going to learn about the getMaximum() method of GregorianCalendar Class with its syntax and example.
Submitted by Preeti Jain, on February 15, 2020
GregorianCalendar Class getMaximum() method
- getMaximum() method is available in java.util package.
- getMaximum() method is used to get the maximum value of the given Calendar field (fi) for this GregorianCalendar instance.
- getMaximum() method is a non-static method, it is accessible with class object only and if we try to access the method with class name then we will get an error.
- getMaximum() method does not throw an exception at the time of returning maximum value of the given field.
Syntax:
public int getMaximum(int fi);
Parameter(s):
- int fi – represents the GregorianCalendar field (fi).
Return value:
The return type of this method is int, it returns maximum value of the given field (fi).
Example:
// Java program to demonstrate the example
// of int getMaximum(int fi) method of GregorianCalendar
import java.util.*;
public class GetMaximumOfGregorianCalendar {
public static void main(String args[]) {
// Instantiating a GregorianCalendar object
GregorianCalendar ca = (GregorianCalendar) GregorianCalendar.getInstance();
// Display current GregorianCalendar
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(GregorianCalendar.MONTH);
//Display maximum value of month
System.out.println("ca.getMaximum(GregorianCalendar.MONTH): " + month);
}
}
Output
ca: Sat Feb 15 09:55:04 GMT 2020
ca.getMaximum(GregorianCalendar.MONTH): 11