Introduction to Java Collections Framework this is test

The Java Collections Framework helps developers manage and organize data. Instead of creating your own data structures, Java provides built-in types like List, Set, Map, etc. 

1. List 

Characteristics :

It is an ordered collection.

it allows duplicates.

Index based access is possible.

Positional manipulation is possible.

Can Contain Null Values.

It is Resizable Dynamically.

Example:


List names = new ArrayList<>(); 
names.add("Alice"); 
names.add("Bob"); 
names.add("Alice"); 
System.out.println(names); // [Alice, Bob, Alice]
  

2. Set 

Characteristics :

it does not allow duplicate elements. 

It has no guarantee of insertion order.

It supports null values (only one null entry allowed).

Example:


Set uniqueNames = new HashSet<>(); 
uniqueNames.add("Alice"); 
uniqueNames.add("Bob"); 
uniqueNames.add("Alice"); 
System.out.println(uniqueNames); // [Alice, Bob]
  

3. Map

Characteristics :

It stores data in key-value pairs.

Duplicate keys are not allowed; values can be duplicated.

Provides quick access to values based on keys.

It has no guarantee of insertion order. 

Example:


Map scoreMap = new HashMap<>(); 
scoreMap.put("Alice", 90); 
scoreMap.put("Bob", 80); 
System.out.println(scoreMap.get("Alice")); // 90
  

Java also includes Queue, Deque, LinkedList, TreeMap, etc., depending on your needs. The Collections class offers helpful methods like sorting, shuffling, or finding min/max values.

Understanding which collection to use and when can make your code efficient and clean. It’s a core part of Java, so every developer should get comfortable with it.

Related Blog