यह एक संग्रह का प्रतिनिधित्व करता है जो प्रसंस्करण से पहले डेटा रखने के लिए अभिप्रेत है। यह फर्स्ट-इन-फर्स्ट-आउट (FIFO) प्रकार की व्यवस्था है। कतार में डाला गया पहला तत्व उससे निकाला गया पहला तत्व होता है।
peek() विधि
यह विधि वर्तमान कतार के शीर्ष पर ऑब्जेक्ट को लौटाती है, बिना इसे हटाए। यदि कतार खाली है तो यह विधि null लौटाती है।
उदाहरण
import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; public class QueueExample { public static void main(String args[]) { Queue queue = new LinkedList(); queue.add("Java"); queue.add("JavaFX"); queue.add("OpenCV"); queue.add("Coffee Script"); queue.add("HBase"); System.out.println("Element at the top of the queue: "+queue.peek()); Iterator it = queue.iterator(); System.out.println("Contents of the queue: "); while(it.hasNext()) { System.out.println(it.next()); } } } आउटपुट
Element at the top of the queue: Java Contents of the queue: Java JavaFX OpenCV Coffee Script Hbase
poll() विधि
Queue इंटरफेस की poll() विधि वर्तमान कतार के शीर्ष पर ऑब्जेक्ट को लौटाती है और इसे हटा देती है। यदि कतार खाली है तो यह विधि null लौटाती है।
उदाहरण
import java.util.Iterator; import java.util.LinkedList; import java.util.Queue; public class QueueExample { public static void main(String args[]) { Queue queue = new LinkedList(); queue.add("Java"); queue.add("JavaFX"); queue.add("OpenCV"); queue.add("Coffee Script"); queue.add("HBase"); System.out.println("Element at the top of the queue: "+queue.poll()); Iterator it = queue.iterator(); System.out.println("Contents of the queue: "); while(it.hasNext()) { System.out.println(it.next()); } } } आउटपुट
Element at the top of the queue: Java Contents of the queue: JavaFX OpenCV Coffee Script HBase