এটি একটি কালেকশন উপস্থাপন করে যা প্রক্রিয়া করার আগে ডেটা ধারণ করার উদ্দেশ্যে। এটি একটি ফার্স্ট-ইন-ফার্স্ট-আউট (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() মেথড
poll() মেথড Queue ইন্টারফেসের বর্তমান কিউর শীর্ষে থাকা অবজেক্ট রিটার্ন করে এবং এটিকে সরিয়ে দেয়। যদি কিউ খালি থাকে তবে এই মেথড 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