Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator
iszero
period

What is Period.isZero() in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

isZero() is an instance method of the Period used to check if all of the values of the three units, i.e., years, months, and days of the Period instance, are zero.

The isZero() method is defined in the Period class. The Period class is defined in the java.time package. To import the Period class, check the following import statement.

import java.time.Period;

Syntax


public boolean isZero()

Parameters

The method accepts no parameters.

Return value

This method returns true if all the values of the three units are zero. Otherwise, it returns false.

Code

In the below code, we check if the Period objects have all of the three unit’s values as zero.

import java.time.Period;
public class Main{
public static void main(String[] args) {
int numMonths = 0;
int numYears = 0;
int numDays = 0;
Period period = Period.of(numYears, numMonths, numDays);
System.out.printf("isZero(%s) = %s\n", period, period.isZero());
numMonths = 0;
numYears = 5;
numDays = 0;
period = Period.of(numYears, numMonths, numDays);
System.out.printf("isZero(%s) = %s\n", period, period.isZero());
}
}

RELATED TAGS

java
communitycreator
iszero
period

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring