Hi,
How to read all elements from java.util.Queue using peek()?. Kindly reply me back. Thanks in advance.
One way of getting the elements from java.util.Queue implementation classes is using poll(),but this method removes the elements from the Queue.Code is as follows:
___________________________________________________________________________
//************* with repective to JDK1.5************
import java.util.Queue;
import java.util.LinkedList;
import org.apache.log4j.*;
public class QueueOffer {
private static Category category = Category.getInstance(QueueOffer.class.getName());
public static void main(
String[] args) {
Queue queue = new LinkedList();
//Add Items To Queue
queue.offer("Sri");
queue.offer("Krishna");
queue.offer("Prasad");
queue.offer("Potluri");
category.info("...Adding Items To Queue..."+queue.toString());
// Retrive Items From Queue.
category.info("....Retriving The Items From Queue... ");
//Iterator iterate = queue.iterator();
Object o;
while( (o=queue.poll())!= null ) {
category.info(" "+o);
}
}
____________________________________________________________________________
My requirement is
just read all elements from the Queue , but elements should not be deleted. This can be done using peek(). But I would like to know how?
Thanks & Regards,
Kris.