HashSet, TreeSet, LinkedHashSet In Hindi

HashSet, TreeSet, LinkedHashSet In Hindi

जावा प्रोग्रामिंग लैंग्वेज में Set इंटरफ़ेस डाटा टाइप स्टोरेज मेथड जावा लैंग्वेज ग्रुप फ्रेमवर्क का एक बिल्ट-इन फीचर्स है, जावा मे सेट डाटा टाइप जावा यूजर को कई इम्पोर्टेन्ट एलिमेंट्स के कलेक्शन को रिप्रेजेंट करने में हेल्प करता है. इसके साथ ही सेट डाटा टाइप में कोई डुप्लीकेट एलिमेंट या वैल्यू रिप्रेजेंट नहीं हो सकते है। जावा प्रोग्राम में Set इंटरफ़ेस में तीन HashSet, TreeSet, और LinkedHashSet सामान्य रूप से यूज़ होने वाले बेसिक सेट कांसेप्ट हैं.

HashSet, TreeSet, LinkedHashSet In Hindi

Three Set interface elements in the popular Java language.

  • HashSet
  • TreeSet
  • LinkedHashSet

जावा में यूज़ हर सेट डाटा टाइप एलिमेंट के अपने यूज़ इम्प्लीमेंटेशन के इंडिविजुअल फंक्शन या फीचर्स होते है, जहा इन सेट डाटा टाइप का इम्पैक्ट और यूज़ के कई यूज़केस हो सकते हैं।

So, let’s take a closer look at the HashSet, TreeSet, and LinkedHashSet in Java programming.

HashSet data type in Java.

जावा प्रोग्राम में HashSet डाटा टाइप Set इंटरफ़ेस डाटा टाइप का एक यूज़फुल इम्प्लीमेंटेशन फीचर्स है, जो जावा प्रोग्राम में सेकेंडरी स्टोरेज के लिए हैश टेबल (रियल में, इंटरली एक HashMap) को यूज़ या फॉलो करता है। जावा हैशसेट डाटा टाइप स्टोरेज डाटा एलिमेंट्स के किसी स्पेशल सीक्वेंस या ऑर्डर को इंडीकेट नहीं करता है।

Special features of the HashSet set data type.

  • No duplicates – जावा प्रोग्राम में डिक्लेअर HashSet ऑटोमेटिकली सेट डुप्लीकेट एलिमेंट वैल्यू को रिमूव कर देता है। यदि जावा यूजर डिक्लेअर सेट डाटा में पहले से स्टोर कोई डाटा एलिमेंट वैल्यू को ऐड करने की ट्राय करते हैं. तो वह एलिमेंट मौजूदा सेट डाटा टाइप में दोबारा ऐड नहीं हो पाएगा।
  • Unordered – जावा प्रोग्राम में डिक्लेअर HashSet सेट डाटा टाइप में स्टोर डाटा एलिमेंट्स अनऑर्डर्ड नेचर के होते हैं। यहाँ स्टोर HashSet सेट डाटा टाइप इस बात की कोई गारंटी नहीं है कि स्टोर HashSet एलिमेंट्स किस ऑर्डर में स्टोर या एक्सट्रेक्ट होंगे। HashSet प्रोग्राम में फ़ास्ट जिसमे HashSet बेसिक ऑपरेशन को अप्लाई करना जैसे कि HashSet एलिमेंट को ऐड करना, HashSet एलिमेंट को रिमूव करना और मेंबरशिप चेक करने के लिए टाइम कॉम्प्लेक्सिटी (O(1)) फीचर्स प्रोवाइड करता है।
  • Not synchronized – जावा में यूज़ HashSet सेट डाटा टाइप डिफ़ॉल्ट रूप से थ्रेड-सेफ़ फीचर्स नहीं है। यदि जावा यूजर को थ्रेड सेफ़्टी फीचर्स चाहिए, तो जावा यूजर इसे एक्सटर्नाली सिंक्रोनाइज़ कर सकते हैं, या Collections.synchronizedSet() फंक्शन मेथड को यूज़ कर सकते हैं।

HashSet is a set data type example.

import java.util.HashSet;

public class HashSetDatatype {

    public static void main(String[] args) {

        HashSet<String> set = new HashSet<>();

        // here we Adding a hashset elements in java

        set.add(“India”);

        set.add(“USA”);

        set.add(“Rusia”);

        set.add(“China”);

        set.add(“Rusia”);  // here it removes Duplicate HashSet element, and this will not be added

        // here it Iterating through the HashSet element

        for (String country : set) {

            System.out.println(country);  // here the hashset Output will be in random order

        }

        // here it Checking for existence of hashset element

        if (set.contains(“India”)) {

            System.out.println(“here India is in the set element”);

        }

        // here we remove existing hashset element

        set.remove(“China”);

        System.out.println(“After remove China hashset element – ” + set);

    }

}

TreeSet data type in Java.

जावा प्रोगाम में एक TreeSet Set डाटा टाइप इसके यूजर को इंटरफ़ेस का एक सेट इम्प्लीटेशन कांसेप्ट प्रोवाइड करता है, जो जावा प्रोग्राम में TreeSet डाटा टाइप में सेकंडरी स्टोरेज के लिए Red-Black ट्री कांसेप्ट को फॉलो करता है। TreeSet डाटा टाइप यूजर डिक्लेअर एलिमेंट्स वैल्यू को उनके नेचुरल स्टोरेज ऑर्डर के अनुसार या इनके क्रिएशन के समय प्रोवाइड किए गए Comparator द्वारा सॉर्टेड ऑर्डर में स्टोर करता है।

Special features of the TreeSet data type.

  • Sorted – TreeSet डाटा टाइप जावा प्रोग्राम में एक एलिमेंट्स का स्टोरेज एलिमेंट ऑर्डर को होल्ड करता है। TreeSet सेट डाटा टाइप में स्टोर एलिमेंट्स डिफ़ॉल्ट रूप से बढ़ते हुए ऑर्डर में स्टोर या डिस्प्ले होते हैं।
  • No Duplicates – TreeSet डाटा टाइप अन्य सेट डाटा टाइप की तरह, जावा यूजर को डुप्लीकेट वैल्यू स्टोरेज परमिशन प्रोवाइड नहीं करता है। यहाँ TreeSet डाटा टाइप में लॉगरिदमिक टाइम कॉम्प्लेक्सिटी – एलिमेंट्स को ऐड करने में, TreeSet एलिमेंट रिमूव करने और चेक करने जैसे TreeSet ऑपरेशन्स की टाइम कॉम्प्लेक्सिटी O(log n) डिफाइन होती है, जो की इसके इंटरनल ट्री स्ट्रक्चर के कारण होती है।
  • Not synchronized – जावा प्रोग्राम में HashSet डाटा टाइप की तरह, TreeSet सेट डाटा टाइप भी सिंक्रोनाइज़्ड फीचर्स अल्लॉव नहीं करता है।

Example of TreeSet data type.

import java.util.TreeSet;

public class TreeSetDataType {

    public static void main(String[] args) {

        TreeSet<String> set = new TreeSet<>();

        // here we Adding a multiple TreeSet data type elements

        set.add(“India”);

        set.add(“USA”);

        set.add(“Rusia”);

        set.add(“China”);

        set.add(“Rusia”);  // here it will remove Duplicate TreeSet element, this will not be added

        // here it Iterating through the TreeSet (sorted order manner)

        for (String country : set) {

            System.out.println(country); 

        }

        // here it Checking for existence of TreeSet element

        if (set.contains(“India”)) {

            System.out.println(“here India is in the set element”);

        }

        // here we Removing an TreeSet element

        set.remove(“China”);

        System.out.println(“After TreeSet element removal – ” + set);

    }

}

LinkedHashSet data type in Java.

जावा प्रोग्रामिंग में LinkedHashSet, Set डाटा बेस इंटरफ़ेस को इम्प्लीमेंटेशन करने में हेल्प करता है, जावा LinkedHashSet हैश टेबल और लिंक्ड लिस्ट के कॉम्बिनेशन को यूज़ या फॉलो करता है। इसके साथ ही LinkedHashSet में यूजर डाटा एलिमेंट्स के इंसर्शन ऑर्डर को मेन्टेन करता है, इसका अर्थ है कि LinkedHashSet डाटा एलिमेंट्स उसी ऑर्डर में स्टोर और प्रोसेस होते हैं, जिन आर्डर में उन्हें जावा यूजर द्वारा ऐड किया गया था।

Special features of the LinkedHashSet data type.

  • Insertion order – जावा HashSet सेट डाटा टाइप के अपोजिट, जिसमें कोई डाटा एलिमेंट स्टोर ऑर्डरिंग नहीं होती है, जावा में यूजर डिक्लेअर एक LinkedHashSet डाटा एलिमेंट्स के उसी ऑर्डर को मेन्टेन रखता है. जिस आर्डर में उन्हें इन्सर्ट या ऐड किया गया था।
  • No duplicates – अन्य डाटा सेट्स की तरह, LinkedHashSet सेट डाटा टाइप डुप्लीकेट वैल्यू और कंटेंट की परमिशन प्रोवाइड नहीं करता है।
  • Fast operation – जावा प्रोग्राम में LinkedHashSet डाटा टाइप नए डाटा एलिमेंट को ऐड, रिमूव, और अन्य कंटेन ऑपरेशन्स, जैसे HashSet के लिए कॉन्सटेंट-टाइम परफॉर्मेंस (O(1)) प्रोवाइड करता है. लेकिन LinkedHashSet में डाटा इंसर्शन ऑर्डर को मेन्टेन रखने के लिए एक्स्ट्रा ओवरहेड को यूज़ करता है।
  • Not synchronized – अन्य सेट्स डाटा टाइप की तरह, LinkedHashSet डाटा टाइप जावा प्रोग्राम में सिंक्रोनाइज़्ड नहीं होते है।

Example of the LinkedHashSet data type.

import java.util.LinkedHashSet;

public class LinkedHashDataType {

    public static void main(String[] args) {

        LinkedHashSet<String> set = new LinkedHashSet<>();

        // here we Adding a LinkedHashSet data elements

        set.add(“India”);

        set.add(“USA”);

        set.add(“Rusia”);

        set.add(“China”);

        set.add(“Rusia”);  // here we declare a Duplicate LinkedHashSet element, that will not be added

        // here it Iterating through the LinkedHashSet (insertion order manner)

        for (String country : set) {

            System.out.println(country);  // Output: India, Rusia, China (insertion order)

        }

        // here it Checking for existence of an LinkedHashSet element

        if (set.contains(“India”)) {

            System.out.println(“India is in the set”);

        }

        // here it Removing LinkedHashSet element

        set.remove(“China”);

        System.out.println(“here After removal LinkedHashSet element – ” + set);

    }

}

Main difference between HashSet, TreeSet, and LinkedHashSet.

Each set FeatureHashSet data typeTreeSet data typeLinkedHashSet data type
Storage OrderingHashSet data typeNo ordering allowed, it means it store set data in (unordered) natureTreeSet data type store data element in Sorted order (ascending, natural order or comparator) for each elementLinkedHashSet data type keep Maintains its data type insertion order
Duplicates natureHashSet data typeDoes not allow duplicates set element valueEven TreeSet data type Does not allow any set duplicates valuesLinkedHashSet data type Does not allow any duplicates set values
Underlying Structure behaviourHashSet data typeuseHash tableTreeSet data type Red-Black Tree (Self-balancing binary search tree) structureIt uses Hash table with linked list structure
Time Complexity set data (Add, Remove, Contains) operationHashSet data use O(1) (average case) while apply operationTreeSet data type use O(log n) during apply operationLinkedHashSet data type O(1) (average case) for data operation
Thread Safety featuresHashSet data type Not synchronizedTreeSet data type Not synchronizedLinkedHashSet data type Not synchronized
Where to Use CaseHashSet data type use in Fast lookup, insert, and delete without concern for data element orderTreeSet data type use where you Need for sorted data elements (natural order or custom comparator) according to needLinkedHashSet data type used When order of data element insertion is matters

HashSet, TreeSet, and LinkedHashSet Java Summary.

  • HashSet – जावा प्रोग्राम में HashSet डाटा टाइप को तब अप्लाई करें। जब जावा यूजर को डाटा एलिमेंट के स्टोरेज ऑर्डर सीक्वेंस की जरूरत न हो और HashSet एलिमेंट को ऐड, रिमूव, और इसके एक्सिस्टेंस को चेक करने के लिए बेस्ट परफॉर्मेंस की ज़रूरत हो. जैसे, फ़ास्ट लुकअप, ऑपरेशन्स आदि है।
  • TreeSet – जावा प्रोग्राम में TreeSet डाटा टाइप को तब अप्लाई करें। जब जावा यूजर को TreeSet सेट डाटा एलिमेंट्स को एक स्पेसिफिक स्पेशल सीक्वेंस में स्टोर करने की ज़रूरत हो, और जावा प्रोग्रामर को TreeSet एलिमेंट्स को ऐड करने, मौजूदा TreeSet एलिमेंट को रिमूव करने और TreeSet से क्वेरी करने के लिए तेज़ लॉगरिदमिक टाइम कॉम्प्लेक्सिटी की ज़रूरत हो।
  • LinkedHashSetजावा प्रोग्रामिंग में LinkedHashSet डाटा टाइप को तब अप्लाई करें। जब जावा यूजर को LinkedHashSet डाटा एलिमेंट्स को उसी सीक्वेंस आर्डर में स्टोर करने की आवश्यकता हो जिस आर्डर में उन्हें इन्सर्ट किया गया था, इसके साथ ही प्रॉपर आर्डर में LinkedHashSet एलिमेंट ऐड, रिमूव, और कंटेन्स ऑपरेशन की आवश्यकता हो।

Leave a Reply