java.util.Calendar isSet(int field)

Description :

This java tutorial shows how to use the isSet(int field) method of Calendar class of java.util package. This method determines if the given calendar field has a value set, including cases that the value has been set by internal fields calculations triggered by a get method call.

Method Syntax :

public final boolean isSet(int field)

Parameter Input :


DataType Parameter Description
int field the calendar field which we want to test if its set


Method Returns :

This method returns true if the given calendar field has a value set; false otherwise.

Compatibility Version :

Requires Java 1.1 and up

Exception :


Discussion :

The Calender isSet(int field) method is used to test if the specified method argument field has been set on this Calendar object. Depending on your project requirements this become will be handy in a situation wherein we have to check if a specific field of our Calendar object is already set or it is still contains the default value which is the value of this calendar after clear().

Java Code Example :

This java example source code demonstrates the use of isSet(int field)  method of Calendar class. Basically we just clear the fields of the calendar object and then test if the fields are set. Its a simple example of using clear, set and isSet method of Calendar class. Though simple as it may seems, the contents are sufficient enough in understanding how these methods works with each other.


import java.util.Calendar;

/* * This example source code demonstrates the use of * isSet(int field) method of Calendar class */

public class CalendarIsSetExample {

public static void main(String

[] args) throws InterruptedException {

Calendar cal = Calendar.getInstance(); // Printing the current time System.out.println("Current time:" + cal.getTime());

//check if year field is set System.out.println("Is the year set? "+cal.isSet(Calendar.YEAR));

// clear the calendar cal.clear(); System.out.println("Time after clear:"+cal.getTime()); // test the year field if it has been set System.out.println("Is the year set? "+cal.isSet(Calendar.YEAR));

} }

Sample Output :

Running the isSet(int field) method example source code of Calendar class will give you the following output:

Calendar isSet(int field) method example

Calendar isSet(int field) method example

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :