Java-util-calendar-isset

提供:Dev Guides
移動先:案内検索

Java.util.Calendar.isSet()メソッド

説明

  • java.util.Calendar.isSet(int field)メソッドは、指定されたカレンダー *field に値が設定されているかどうかを確認します。値がgetメソッドの呼び出しによってトリガーされる内部フィールドの計算によって設定されている場合が含まれます。

宣言

以下は java.util.Calendar.isSet メソッドの宣言です

public final boolean isSet(int field)

パラメーター

*field* -チェックするフィールド。

戻り値

このメソッドは、指定されたカレンダーフィールドに値が設定されている場合、 true を返します。それ以外の場合は false

例外

NA

次の例は、java.util.calendar.isSet()メソッドの使用方法を示しています。

package com.finddevguides;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {

     //create a calendar
      Calendar cal = Calendar.getInstance();

     //display the current calendar
      System.out.println("Current Day is " + cal.get(Calendar.DAY_OF_MONTH));

     //determine if the given calendar field has a value set
      boolean b = cal.isSet(Calendar.DAY_OF_MONTH);
      System.out.println("Day of month is set: " + b);

     //clear day of month
      cal.clear(Calendar.DAY_OF_MONTH);

     //determine if the given calendar field has a value set
      b = cal.isSet(Calendar.DAY_OF_MONTH);
      System.out.println("Day of month is set: " + b);
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Current Day is 6
Day of month is set: true
Day of month is set: false