Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
ChronoPeriod isZero() method in Java with Examples
Next article icon

Duration isZero() method in Java with Examples

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

The isZero() method of Duration Class in java.time package is used to check if this duration is of 0 length ot not. It returns a boolean value depicting the same.

Syntax:

  public boolean isZero()  

Parameters: This method do not accepts any parameter.

Return Value: This method returns a boolean value. If the length is of 0 length, then it returns true. Else it returns false.

Below examples illustrate the Duration.isZero() method:

Example 1:




// Java code to illustrate isZero() method
  
import java.time.Duration;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get the text
        String time = "P2DT3H4M";
  
        // Duration using parse() method
        Duration duration = Duration.parse(time);
  
        // Duration using isZero() method
        boolean isZero = duration.isZero();
  
        System.out.println(isZero);
    }
}
 
 
Output:
  false  

Example 2:




// Java code to illustrate isZero() method
  
import java.time.Duration;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get the text
        String time = "P0DT0H0M";
  
        // Duration using parse() method
        Duration duration = Duration.parse(time);
  
        // Duration using isZero() method
        boolean isZero = duration.isZero();
  
        System.out.println(isZero);
    }
}
 
 
Output:
  true  

Reference: https://docs.oracle.com/javase/9/docs/api/java/time/Duration.html#isZero–



Next Article
ChronoPeriod isZero() method in Java with Examples

C

code_r
Improve
Article Tags :
  • Java
  • Java-Duration
  • Java-Functions
  • Java-time package
Practice Tags :
  • Java

Similar Reads

  • Duration isNegative() method in Java with Examples
    The isNegative() method of Duration Class in java.time package is used to check if this duration is negative or not. It returns a boolean value depicting the same. Syntax: public boolean isNegative() Parameters: This method do not accepts any parameter. Return Value: This method returns a boolean va
    1 min read
  • Duration abs() method in Java with Examples
    The abs() method of Duration Class in java.time package is used to get an immutable copy of this duration with the absolute duration. Syntax: public Duration abs() Parameters: This method do not accepts any parameter. Return Value: This method returns a Duration which is an immutable copy of the exi
    1 min read
  • Duration getNano() method in Java with Examples
    The getNano() method of Duration Class in java.time package is used to get the nanos value of this duration. Syntax: public long getNano() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value of the nanos of this duration. Below examples illustrate the
    1 min read
  • ChronoPeriod isZero() method in Java with Examples
    The isZero() method of ChronoPeriod class in Java is used to check whether all of the three YEAR, MONTH, DAYS in this period are zero. To check the zero periods, this function is used widely. A zero period is the period where all of the three YEAR, MONTHS and DAYS are zero. Syntax: boolean isZero()
    2 min read
  • Duration toDays() method in Java with Examples
    The toDays() method of Duration Class in java.time package is used get the value of this duration in number of days. Syntax: public long toDays() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of days in this duration. Below e
    1 min read
  • Duration getUnits() method in Java with Examples
    The getUnits() method of Duration Class in java.time package is used to get the list of units that are supported by this duration. Syntax: public List<TemporalUnit> getUnits() Parameters: This method do not accepts any parameter. Return Value: This method returns a list of units that are suppo
    1 min read
  • Duration getSeconds() method in Java with Examples
    The getSeconds() method of Duration Class in java.time package is used to get the second value of this duration. Syntax: public long getSeconds() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value of the seconds of this duration. Below examples illus
    1 min read
  • Duration toNanos() method in Java with Examples
    The toNanos() method of Duration Class in java.time package is used get the value of this duration in number of nano-seconds. Syntax: public long toNanos() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of nano-seconds in this
    1 min read
  • Duration toHours() method in Java with Examples
    The toHours() method of Duration Class in java.time package is used get the value of this duration in number of hours. Syntax: public long toHours() Parameters: This method do not accepts any parameter. Return Value: This method returns a long value which is the number of hours in this duration. Bel
    1 min read
  • Duration negated() method in Java with Examples
    The negated() method of Duration Class in java.time package is used to get an immutable copy of this duration with the duration negated. Syntax: public Duration negated() Parameters: This method do not accepts any parameter. Return Value: This method returns a Duration which is an immutable copy of
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences