Android-এ আনসর্টেড (Unsorted) LinkedList-এ ডুপ্লিকেট সরিয়ে ফেলা
এই টিউটোরিয়ালে আমরা দেখব কিভাবে HashSet ব্যবহার করে একটি আনসর্টেড LinkedList-এর ডুপ্লিকেট এলিমেন্টগুলো সরিয়ে অনIQUE মানের সেট তৈরি করা যায়। নোট: HashSet অর্ডার রক্ষা করে না।
প্রয়োজনীয় ধাপসমূহ
ধাপ ১: নতুন প্রজেক্ট তৈরি করুন
Android Studio → File → New Project → প্রয়োজনীয় ডিটেইলস পূরণ করুন।
ধাপ ২: লেআউট ফাইল (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:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:gravity="center" />
</LinearLayout>
ধাপ ৩: MainActivity.java
package com.example.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import java.util.HashSet;
import java.util.LinkedList;
public class MainActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.P)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinkedList<Integer> linkedList = new LinkedList<>();
linkedList.add(2);
linkedList.add(8);
linkedList.add(2);
linkedList.add(5);
linkedList.add(7);
linkedList.add(5);
linkedList.add(9);
// HashSet ব্যবহার করে ডুপ্লিকেট সরান (অর্ডার রক্ষা হয় না)
HashSet<Integer> hashSet = new HashSet<>(linkedList);
TextView textView = findViewById(R.id.text);
textView.setText("ডুপ্লিকেট বাদ (অর্ডার নেই): " + hashSet.toString());
}
}
ফলাফল
ইনপুট: [2, 8, 2, 5, 7, 5, 9]
আউটপুট (HashSet - র্যান্ডম অর্ডার): [2, 5, 7, 8, 9] (অর্ডার ভিন্ন হতে পারে)

HashSet vs LinkedHashSet - পার্থক্য
| বৈশিষ্ট্য | HashSet | LinkedHashSet |
|---|---|---|
| ডুপ্লিকেট অ্যালাউ করে? | না | না |
| ইনসারশন অর্ডার রক্ষা করে? | না (Unpredictable) | হ্যাঁ |
| পারফরম্যান্স | কিছুটা দ্রুত | HashSet-এর চেয়ে একটু ধীর |