Online Java Compiler By
JavaTpoint.com
import java.util.*; import java.util.concurrent.LinkedTransferQueue; class Patients{ String Pname; public Patients(String pname) { Pname = pname; } public String toString(){ return this.Pname; } } public class LinkedTransferQueueSizeExample2 { static int i=1; public static void main(String[] args) { Patients patient1 = new Patients("John"); Patients patient2 = new Patients("Harry"); Patients patient3 = new Patients("Peter"); Patients patient4 = new Patients("Marry"); Patients patient5 = new Patients("Jack"); Patients patient6 = new Patients("Lucene"); LinkedTransferQueue
queue = new LinkedTransferQueue
(); List
list = new ArrayList
(); queue.add(patient1); queue.add(patient2); queue.add(patient3); queue.add(patient4); queue.add(patient5); queue.add(patient6); // returns the total size of the queue System.out.println("Total Patients = "+queue.size()); for(Patients xyz : queue){ System.out.println(i++ +"."+xyz); } list.add(patient1); list.add(patient2); list.add(patient3); list.add(patient4); i=1; System.out.println("Patients recovered and discharged : "+list); queue.removeAll(list); System.out.println("Patients left in the hospital = "+queue.size()); for (Patients xyz : queue) { System.out.println(i++ +"."+xyz); } } }
Output