কম্পিউটার টিউটোরিয়াল

Android-এ ConcurrentLinkedQueue-এ এলিমেন্ট খুঁজে বের করার পদ্ধতি

পরিচয়

উদাহরণের আগে জানা দরকার ConcurrentLinkedQueue কী। এটি লিংকড নোডের উপর ভিত্তি করে একটি unbounded queue। একাধিক থ্রেড নিরাপদে queue-র এলিমেন্ট অ্যাক্সেস করতে পারে। এলিমেন্টগুলো FIFO কৌশল অনুযায়ী যায় এবং টেইল থেকে ইনসার্ট হয়। এটি null ভ্যালু অনুমতি দেয় না।

এই উদাহরণটি দেখাবে কীভাবে Android-এ ConcurrentLinkedQueue-এ এলিমেন্ট খুঁজে বের করা যায়।

ধাপ ১: নতুন প্রজেক্ট তৈরি করুন

Android Studio-তে যান: File → New Project এবং প্রয়োজনীয় বিবরণ পূরণ করে একটি নতুন প্রজেক্ট তৈরি করুন।

ধাপ ২: লেয়াউট XML কনফিগার করুন

res/layout/activity_main.xml ফাইলে নিচের কোডটি যোগ করুন:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:app="https://schemas.android.com/apk/res-auto"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:gravity="center"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:id="@+id/actionEvent"
        android:textSize="40sp"
        android:layout_marginTop="30dp"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

</LinearLayout>

উপরের কোডে ConcurrentLinkedQueue-এর এলিমেন্টগুলো দেখানোর জন্য একটি TextView ব্যবহার করা হয়েছে।

ধাপ ৩: MainActivity.java-তে লজিক লিখুন

src/MainActivity.java ফাইলে নিচের কোডটি যোগ করুন:

package com.example.myapplication;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.util.concurrent.ConcurrentLinkedQueue;

public class MainActivity extends AppCompatActivity {
    ConcurrentLinkedQueue concurrentLinkedQueue;
    String head;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        concurrentLinkedQueue = new ConcurrentLinkedQueue<String>();
        final TextView actionEvent = findViewById(R.id.actionEvent);

        concurrentLinkedQueue.add("sai");
        concurrentLinkedQueue.add("ram");
        concurrentLinkedQueue.add("krishna");
        concurrentLinkedQueue.add("prasad");
        concurrentLinkedQueue.add("ram");

        actionEvent.setText("" + concurrentLinkedQueue);

        actionEvent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                actionEvent.setText("" + concurrentLinkedQueue.contains("prasad"));
            }
        });
    }
}

অ্যাপ্লিকেশন চালান

আপনার Android ডিভাইস কম্পিউটারের সাথে সংযুক্ত করুন। Android Studio-তে প্রজেক্টের একটি Activity ফাইল খুলুন এবং টুলবারের Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস নির্বাচন করুন। ডিফল্ট স্ক্রিন প্রদর্শিত হবে:

Android-এ ConcurrentLinkedQueue-এ এলিমেন্ট খুঁজে বের করার পদ্ধতি

এখন TextView-এ ক্লিক করলে নিচের ফলাফলটি দেখাবে:

Android-এ ConcurrentLinkedQueue-এ এলিমেন্ট খুঁজে বের করার পদ্ধতি

  1. অ্যান্ড্রয়েডে ConcurrentLinkedQueue-এ poll() কীভাবে ব্যবহার করবেন?

  2. অ্যান্ড্রয়েডে ConcurrentLinkedQueue-এ remove() কীভাবে ব্যবহার করবেন?

  3. অ্যান্ড্রয়েডে ConcurrentLinkedQueue-এ size() কীভাবে ব্যবহার করবেন?

  4. অ্যান্ড্রয়েড ডিভাইসের সিরিয়াল নম্বর বের করার পদ্ধতি