Calendar class isSet(int field)method example
Determines if the given calendar field has a value set.
Calendar class isSet(int field)method example. This example shows you how to use isSet(int field) method.This method Determines if the given calendar field has a value set.
Here is the code:-
/*
* @Program that 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.
* IsSet.java
* Author:-RoseIndia Team
* Date:-23-May-2008
*/
import java.util.*;
public class IsSet {
public static void main(String[] args) {
Calendar c= Calendar.getInstance();
//Displays the current calendar
System.out.println(" Current Day is "+c.get(Calendar.DAY_OF_MONTH));
// Sets the given calendar field to the given value.
c.set(Calendar.DAY_OF_MONTH,24);
System.out.println(" Next Day is "+c.get(Calendar.DAY_OF_MONTH));
//Determines if the given calendar field has a value set
boolean b=c.isSet(Calendar.YEAR);
System.out.println("Is set " +b);
}
} |
Output of the program:-
Current Day is 24
Next Day is 24
Is set true |
|