Java GregorianCalendar .isLeapYear (int year)

Syntax

GregorianCalendar.isLeapYear(int year) has the following syntax.

public boolean isLeapYear(int year)

Example

In the following code shows how to use GregorianCalendar.isLeapYear(int year) method.


/*  ww w .j  a v  a  2 s .  c  o m*/
import java.util.*;

public class Main {

   public static void main(String[] args) {

      GregorianCalendar cal =
              (GregorianCalendar) GregorianCalendar.getInstance();

      // check if it is a leap year
      boolean isLeapYear = cal.isLeapYear(cal.get(GregorianCalendar.YEAR));
      System.out.println("Is leap year:" + isLeapYear);

      // check if 2014 is a leap year
      isLeapYear = cal.isLeapYear(2014);
      System.out.println("Is leap year:" + isLeapYear);

   }
}

The code above generates the following result.