Thursday, 29 March 2018

How to use equal method of Period Class | Java 8 Date and Time


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=ev1oO0AmOYU&list=UUhwKlOVR041tngjerWxVccw

PeriodDemo.java

import java.time.Period;

public class PeriodDemo
{

    public static void main(String[] args)
    {

        Period period1 = Period.ofDays(12);
        System.out.println("period1 = " + period1);
       
        Period period2 = Period.ofDays(12);
        System.out.println("period2 = " + period2);
        /*
         * Parameters:
         *
         * obj - the object to check, null returns false
         *
         * Returns:
         *
         * true if this is equal to the other period
         */

        boolean isEqual = period1.equals(period2);
        System.out.println("isEqual = " + isEqual);

    }

}

Output

period1 = P12D
period2 = P12D
isEqual = true

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/PeriodDemo_equals.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/PeriodDemo_equals

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/755fea7aeca931764d09d2ae6d0900a44d7186bb/BasicJava_2018/PeriodDemo_equals/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a comment