import
java.util.Iterator;
import
java.util.concurrent.LinkedBlockingQueue;
import
java.util.concurrent.BlockingQueue;
public
class
GFG {
public
void
removeDemo()
throws
InterruptedException
{
int
capacityOfQueue =
5
;
BlockingQueue<Employee> BQ
=
new
LinkedBlockingQueue<Employee>(capacityOfQueue);
Employee emp1 =
new
Employee(
"Ranjeet"
,
"Tester"
,
"29000"
,
27
);
Employee emp2 =
new
Employee(
"Sanjeet"
,
"Manager"
,
"98000"
,
34
);
Employee emp3 =
new
Employee(
"Karan"
,
"Analyst"
,
"44000"
,
30
);
BQ.put(emp1);
BQ.put(emp2);
BQ.put(emp3);
System.out.println(
"Before removing Elements"
);
Iterator itr = BQ.iterator();
while
(itr.hasNext())
System.out.println(itr.next());
BQ.remove(emp2);
BQ.remove(emp1);
System.out.println(
"After removing Some Elements"
);
itr = BQ.iterator();
while
(itr.hasNext())
System.out.println(itr.next());
}
public
class
Employee {
public
String name;
public
String position;
public
String salary;
public
int
Age;
Employee(String name, String position,
String salary,
int
age)
{
this
.name = name;
this
.position = position;
this
.salary = salary;
this
.Age = age;
}
@Override
public
String toString()
{
return
"Employee [name="
+ name +
", position="
+ position +
", salary="
+ salary +
", Age="
+ Age +
"]"
;
}
}
public
static
void
main(String[] args)
{
GFG gfg =
new
GFG();
try
{
gfg.removeDemo();
}
catch
(InterruptedException e) {
e.printStackTrace();
}
}
}