ConcurrentLinkedQueue क्या है?
ConcurrentLinkedQueue एक अनबाउंडेड थ्रेड-सेफ कतार है जो लिंक्ड नोड्स पर आधारित है। यह FIFO क्रम का पालन करती है और नल मानों की अनुमति नहीं देती।
उदाहरण: isEmpty() मेथड का उपयोग
यह उदाहरण दर्शाता है कि Android में ConcurrentLinkedQueue के isEmpty() मेथड का उपयोग कैसे करें।
चरण 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.ConcurrentLinkedQueue;
public class MainActivity extends AppCompatActivity {
ConcurrentLinkedQueue<String> concurrentLinkedQueue;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
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);
// क्लिक पर isEmpty() चेक करें
actionEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean empty = concurrentLinkedQueue.isEmpty();
actionEvent.setText("" + empty);
}
});
}
}
ऐप चलाएं और परीक्षण करें
ऐप चलाएं। प्रारंभ में कतार के तत्व दिखेंगे (isEmpty() false लौटाएगा)। TextView पर क्लिक करने पर false प्रदर्शित होगा। यदि कतार खाली होती तो true लौटाता।

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

मुख्य बिंदु
- isEmpty() मेथड जांचता है कि कतार खाली है या नहीं।
- खाली होने पर true, अन्यथा false लौटाता है।
- ConcurrentLinkedQueue लॉक-फ्री और थ्रेड-सेफ है।