I've a priority queue in which I've put several objects. These objects are from a class Prod that has the following fields:
int Id;
String Gtin;
String Msg;
so my queue looks like this:
PriorityQueue<Prod> pq= new PriorityQueue<Prod>();
pq.add(new Prod(1,"454545","Counter"));
pq.add(new Prod(1,"676767","Counter"));
pq.add(new Prod(1,"787878","Counter"));
pq.add(new Prod(2,"232323","FLoor"));
pq.add(new Prod(2,"323232","Floor"));
pq.add(new Prod(2,"989898","Floor"));
I am then using the iterator to fetch the elements
Iterator iterator = pq.iterator();
while (iterator.hasNext()){
Object prod= iterator.next();
System.out.println("Prod:"+ prod);
}
However, I need to fetch all the Gtins belonging to Id 1 and put them into a file i.e. "454545","676767","787878" for Id 1 needs to be extracted in this example and the same should be repeated for all other Ids. I don't know how to do this. Any help would be truly appreciated.
Thanks