Thursday, October 16, 2025
HomeLanguagesJavaCalendar isSet() Method in Java with Examples

Calendar isSet() Method in Java with Examples

The isSet(int calndr_field) method in Calendar class is used to check whether the given calendar field has a value set or not. All the Cases for which the values have been set by the calculations of the internal field are triggered by a get method call.

Syntax: 

public final boolean isSet(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 either returns True if the value of the calendar field is set else it returns False.

Below programs illustrate the working of isSet() Method of Calendar class:

Example 1: 

Java




// Java code to illustrate
// isSet() method
   
import java.util.*;
public class CalendarDemo {
    public static void main(String args[])
    {
   
        // Creating a calendar object
        Calendar calndr = Calendar.getInstance();
   
        // Displaying the calendar object
        System.out.println("The Year is: "
                           + calndr.get(Calendar.YEAR));
   
        // Querying for the value if set or not
        boolean val = calndr.isSet(Calendar.YEAR);
        System.out.println("Is the"
                           + " Value set? " + val);
   
        // Clearing the instance
        calndr.clear(Calendar.YEAR);
   
        // Performing isSet() operation
        val = calndr.isSet(Calendar.YEAR);
        System.out.println("Is the"
                           + " Value set? " + val);
    }
}


Output: 

The Year is: 2019
Is the Value set? true
Is the Value set? false

 

Example 2: 

Java




// Java code to illustrate
// isSet() method
   
import java.util.*;
public class CalendarDemo {
    public static void main(String args[])
    {
   
        // Creating a calendar object
        Calendar calndr = Calendar.getInstance();
   
        // Displaying the calendar object
        System.out.println("Todays Day is: "
                           + calndr.get(
                                 Calendar.DAY_OF_MONTH));
   
        // Querying for the value if set or not
        boolean val
            = calndr.isSet(Calendar.DAY_OF_MONTH);
        System.out.println("Is the"
                           + " Value set? " + val);
   
        // Clearing the instance
        calndr.clear(Calendar.DAY_OF_MONTH);
   
        // Performing isSet() operation
        val = calndr.isSet(Calendar.DAY_OF_MONTH);
        System.out.println("Is the"
                           + " Value set? " + val);
    }
}


Output: 

Todays Day is: 21
Is the Value set? true
Is the Value set? false

 

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS