কম্পিউটার

জাভাতে কিউ ইন্টারফেসের পিক(), পোল() এবং রিমুভ() পদ্ধতির মধ্যে পার্থক্য?


এটি একটি সংগ্রহের প্রতিনিধিত্ব করে যা প্রক্রিয়াকরণের আগে ডেটা ধরে রাখার জন্য ইন্ডেন্ট করা হয়। এটি ফার্স্ট-ইন-ফার্স্ট-আউট (FIFO) ধরনের একটি ব্যবস্থা। সারিতে রাখা প্রথম উপাদানটি এটি থেকে নেওয়া প্রথম উপাদান।

পিক() পদ্ধতি

এই পদ্ধতিটি বর্তমান সারির শীর্ষে বস্তুটিকে রিটার্ন করে, এটি অপসারণ না করে। সারি খালি থাকলে এই পদ্ধতিটি শূন্য দেয়।

উদাহরণ

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
public class QueueExample {
   public static void main(String args[]) {
      Queue<String> queue = new LinkedList<String>();
      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<String> 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

পোল() পদ্ধতি

পিক() সারির পদ্ধতি ইন্টারফেস বর্তমান সারির শীর্ষে বস্তুটি ফেরত দেয় এবং এটি সরিয়ে দেয়। সারি খালি থাকলে এই পদ্ধতিটি শূন্য দেয়।

উদাহরণ

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
public class QueueExample {
   public static void main(String args[]) {
      Queue<String> queue = new LinkedList<String>();
      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<String> 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

  1. জাভাতে ব্যতিক্রম এবং ত্রুটির মধ্যে পার্থক্য

  2. জাভাতে সিরিয়ালাইজেশন এবং এক্সটারনালাইজেশনের মধ্যে পার্থক্য

  3. জাভাতে ইটারেটর এবং গণনার মধ্যে পার্থক্য

  4. জাভাতে অ্যারেলিস্ট এবং হ্যাশসেটের মধ্যে পার্থক্য