Online Java Compiler By
JavaTpoint.com
import java.sql.Timestamp; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; class BirthTime { static int i = 1; public String name; Timestamp ts1; BirthTime(String name, Timestamp ts1 ) { this.name = name; this.ts1=ts1; } public String toString(){ return this.name; } } public class JavaTimestampCompareToExample2 { public static void main(String[] args) { BirthTime name1 = new BirthTime("Reema", Timestamp.valueOf("2018-09-01 09:01:15")); BirthTime name2 = new BirthTime("Geetanjali",Timestamp.valueOf("2018-09-01 09:01:18")); int capacity = 100; BlockingQueue
queue = new ArrayBlockingQueue
(capacity); queue.add(name1); queue.add(name2); if(queue.poll().ts1.compareTo(queue.poll().ts1)>0){ System.out.println("Reema's birthTime is greater than Geetanjali"); } else{ System.out.println("Geetanjali's birthTime is greater than Reema"); } } }
Output