Home » Java programming language

Java Calendar isSet() Method with Example

Calendar Class isSet() method: Here, we are going to learn about the isSet() method of Calendar Class with its syntax and example.
Submitted by Preeti Jain, on February 01, 2020

Calendar Class isSet() method

  • isSet() method is available in java.util package.
  • isSet() method is used to test whether the given field of this calendar is set or not it returns true when the given parameter (fi) has been set by internal field interpretations.
  • isSet() 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.
  • isSet() method does not throw an exception at the time of checking the given field is set.

Syntax:

    public final boolean isSet(int fi);

Parameter(s):

  • int fi – represents the calendar field(fi) to be tested.

Return value:

The return type of the method is boolean, it returns true when the given calendar field is set otherwise it returns false.

Example:

// Java Program to demonstrate the example of
// boolean isSet(int fi) method of Calendar

import java.util.*;

public class IsSet {
    public static void main(String args[]) {
        // Instantiating a Calendar object
        Calendar ca = Calendar.getInstance();

        System.out.println("ca =" + ca.getTime());

        // By using isSet(int fi) method is to 
        // check the given field is set or
        // not of this Calendar
        boolean status = ca.isSet(Calendar.MONTH);

        //Display status
        System.out.println("ca.isSet(Calendar.MONTH): " + status);
    }
}

Output

ca =Mon Jan 27 08:38:21 GMT 2020
ca.isSet(Calendar.MONTH): true


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.