ConcurrentLinkedDeque क्या है?
ConcurrentLinkedDeque एक अनबाउंडेड थ्रेड-सेफ डीक्यू है जो लिंक्ड नोड्स पर आधारित है। एकाधिक थ्रेड्स सुरक्षित रूप से डीक्यू के तत्वों तक पहुंच सकते हैं।
उदाहरण: pollFirst() मेथड का उपयोग
यह उदाहरण दर्शाता है कि Android में ConcurrentLinkedDeque के pollFirst() मेथड का उपयोग कैसे करें। pollFirst() डीक्यू के पहले तत्व को हटाकर लौटाता है। खाली होने पर null लौटाता है।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project चुनें।
चरण 2: लेआउट फ़ाइल (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>
चरण 3: 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.ConcurrentLinkedDeque;
public class MainActivity extends AppCompatActivity {
ConcurrentLinkedDeque<String> concurrentLinkedDeque;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
concurrentLinkedDeque = new ConcurrentLinkedDeque<>();
final TextView actionEvent = findViewById(R.id.actionEvent);
// तत्व जोड़ना
concurrentLinkedDeque.add("sai");
concurrentLinkedDeque.add("ram");
concurrentLinkedDeque.add("krishna");
concurrentLinkedDeque.add("prasad");
actionEvent.setText("" + concurrentLinkedDeque);
// क्लिक पर pollFirst() से पहला तत्व हटाएं
actionEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
concurrentLinkedDeque.pollFirst();
actionEvent.setText("" + concurrentLinkedDeque);
}
});
}
}
ऐप चलाएं और परीक्षण करें
ऐप चलाएं। प्रारंभ में डीक्यू के तत्व दिखेंगे। TextView पर क्लिक करने पर पहला तत्व हटकर शेष डीक्यू प्रदर्शित होगा।

क्लिक करने के बाद परिणाम:

मुख्य बिंदु
- pollFirst() डीक्यू के पहले तत्व को हटाकर लौटाता है।
- खाली होने पर null लौटाता है (exception नहीं फेंकता)।
- ConcurrentLinkedDeque लॉक-फ्री और थ्रेड-सेफ है।
- removeFirst() के विपरीत, यह खाली डीक्यू पर exception नहीं फेंकता।