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.
List names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
names.add("Alice");
System.out.println(names); // [Alice, Bob, Alice]
it does not allow duplicate elements.
It has no guarantee of insertion order.
It supports null values (only one null entry allowed).
Set uniqueNames = new HashSet<>();
uniqueNames.add("Alice");
uniqueNames.add("Bob");
uniqueNames.add("Alice");
System.out.println(uniqueNames); // [Alice, Bob]
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.
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.
May 16, 2025
Java 17 is a long-term support (LTS) release, which means it’s stable and will be supported for years. It introduces some great features that make Java development cleaner and more modern. Here are 5 features that stand out:
May 16, 2025
Even experienced developers make some common Java mistakes. Let’s look at a few, with examples and how to avoid them.