Java Collections — Free Java Tutorial
Learn Java Collections in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Java Collections in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Java Collections in Java
Java Collections Framework provides pre-built data structures. The most used: ArrayList (dynamic array — like Python list), HashMap (key-value pairs — like Python dict), LinkedList, HashSet, TreeMap.
ArrayList<Type>: A resizable list. Unlike arrays, it grows automatically. Key methods: add(), get(), remove(), size(), contains(), indexOf(), clear(), sort(). Use when you need an ordered, indexed list that can grow.
HashMap<K, V>: Stores key-value pairs with O(1) lookup by key. Key methods: put(), get(), remove(), containsKey(), containsValue(), keySet(), values(), entrySet(). Use when you need fast lookups by key (like a phone book or dictionary).
Java Collections — Syntax
// ArrayList
ArrayList<String> list = new ArrayList<>();
list.add("item");
list.get(0);
list.remove(0);
list.size();
// HashMap
HashMap<String, Integer> map = new HashMap<>();
map.put("Arjun", 85);
map.get("Arjun"); // 85
map.containsKey("key");
Learn Java Collections step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →