MCAWALA

Java Vertical Menu

Java Collections Framework क्या है? – आसान हिंदी में

📦 Java Collections का मतलब

Java में Collections Framework एक powerful tool है जिससे हम data (objects) को store और manage करते हैं। इसका इस्तेमाल तब होता है जब हमें एक ही type के कई values एक साथ संभालने होते हैं।

🧠 Collections Interfaces

Interface Description
List Ordered collection, duplicate values allow करता है
Set Unordered collection, duplicate values allow नहीं करता
Map Key-Value pairs में data store करता है

🔹 List Example – ArrayList

import java.util.ArrayList;

public class Example {
    public static void main(String[] args) {
        ArrayList<String> names = new ArrayList<>();
        names.add("Amit");
        names.add("Rahul");
        names.add("Amit");
        System.out.println(names);
    }
}

🔹 Set Example – HashSet

import java.util.HashSet;

public class Example {
    public static void main(String[] args) {
        HashSet<String> items = new HashSet<>();
        items.add("Pen");
        items.add("Book");
        items.add("Pen");
        System.out.println(items);
    }
}

🔹 Map Example – HashMap

import java.util.HashMap;

public class Example {
    public static void main(String[] args) {
        HashMap<Integer, String> students = new HashMap<>();
        students.put(1, "Amit");
        students.put(2, "Suman");
        students.put(3, "Amit");
        System.out.println(students);
    }
}

💡 Collections के फायदे

  • Dynamic size – array की तरह fixed नहीं
  • Sorting, searching जैसे operations आसान
  • Multiple structures और algorithms
  • Code reuse और performance better

🧠 Summary Table

Collection Type Class Duplicates Allowed? Order Maintained?
List ArrayList Yes Yes
Set HashSet No No
Map HashMap Values: Yes, Keys: No No

🔚 निष्कर्ष

Java Collections Framework Java developers के लिए एक ज़रूरी टूल है। List, Set, और Map जैसे structures आपको data को efficiently manage करने में मदद करते हैं। अगर आप Java सीख रहे हैं, तो collections समझना बहुत जरूरी है।