Skip to content
Related Articles

Related Articles

Improve Article

Calendar getMaximum() method in Java with Examples

  • Last Updated : 19 Feb, 2019

The getMaximum(int calndr_field) method in Calendar class is used to return the maximum value for the given calendar field(int calndr_field) of this Calendar instance.

Syntax:

public abstract int getMaximum(int calndr_field)

Parameters: The method takes one parameter calndr_field that refers to the calendar field which is to be operated upon.

Return Value: The method returns the maximum value for the passed calendar field.

Below programs illustrate the working of getMaximum() Method of Calendar class:
Example 1:






// Java code to illustrate
// getMaximum() method
  
import java.util.*;
  
public class Calendar_Demo {
    public static void main(String args[])
    {
  
        // Creating a calendar
        Calendar calndr = Calendar.getInstance();
  
        // Getting the required months
        System.out.println("Required days: "
                           + calndr.get(Calendar.DAY_OF_WEEK));
  
        // Getting the lowest maximum month
        int max_day = calndr.getMaximum(Calendar.DAY_OF_WEEK);
  
        // Displaying the results
        System.out.println("The Maximum"
                           + " days: " + max_day);
    }
}

Example 2:




// Java code to illustrate
// getMaximum() method
  
import java.util.*;
  
public class Calendar_Demo {
    public static void main(String args[])
    {
  
        // Creating a calendar
        Calendar calndr = new GregorianCalendar(2018, 6, 10);
  
        // Getting the required months
        System.out.println("Required Months: "
                           + calndr.get(Calendar.MONTH));
  
        // Getting the lowest maximum month
        int max_month = calndr.getMaximum(Calendar.MONTH);
  
        // Displaying the results
        System.out.println("The"
                           + " Maximum months: " + max_month);
    }
}

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getMaximum-int-

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :