Online Java Compiler By
JavaTpoint.com
import java.util.Collection; import java.util.concurrent.ConcurrentLinkedQueue; class Employee{ public String name; static String date; public Employee(String name, String date) { this.name = name; this.date = date; } public String toString(){ return this.name+" is present on "+this.date; } } public class JavaCollectionContainsExample3 { public static void main(String[] args) { Collection
queue = new ConcurrentLinkedQueue
(); Employee employee1=new Employee("Rahul","12.08.18"); Employee employee2=new Employee("Geeta","12.08.18"); Employee employee3=new Employee("Sham","12.08.18"); Employee employee4=new Employee("Ravi","12.08.18"); queue.add(employee1); queue.add(employee2); queue.add(employee3); queue.add(employee4); //will check if the queue contains this value or not if (queue.contains(employee3)){ System.out.println(employee2); } else{ System.out.println("This name is not in the list"); } } }
Output