ConcurrentLinkedQueue क्या है?
ConcurrentLinkedQueue एक अनबाउंडेड थ्रेड-सेफ कतार है जो लिंक्ड नोड्स पर आधारित है। यह FIFO क्रम का पालन करती है और नल मानों की अनुमति नहीं देती।
उदाहरण: clear() मेथड का उपयोग
यह उदाहरण दर्शाता है कि Android में ConcurrentLinkedQueue के clear() मेथड का उपयोग कैसे करें।
चरण 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);
// क्लिक पर clear() करें
actionEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
concurrentLinkedQueue.clear();
actionEvent.setText("" + concurrentLinkedQueue);
}
});
}
}
ऐप चलाएं और परीक्षण करें
ऐप चलाएं। प्रारंभ में कतार के तत्व दिखेंगे। TextView पर क्लिक करने पर clear() के बाद खाली कतार प्रदर्शित होगी।

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

मुख्य बिंदु
- clear() मेथड कतार से सभी तत्वों को हटा देता है।
- ConcurrentLinkedQueue में clear() थ्रेड-सेफ है।
- यह लॉक-फ्री एल्गोरिदम का उपयोग करता है।