Java Collections and Generics Tutorials from Basics to Best Practices
- Details
- Written by Nam Ha Minh
- Last Updated on 05 March 2024   |   Print Email
If you're looking for a complete guide to learn how to use collections in Java programming language, this page is exactly what you need. Or if you're an experienced Java developer who wants to refresh your knowledge in Java collections and generics, you've also come to the right place.
You know, Java Collections framework provides a set of reusable data structures and algorithms that make programmer's jobs easier. Any Java programmers must learn to use collections fluently, which help creating robust and efficient applications of any kinds because data structures are the heart of any computer programs.
While Java Collections framework provides reusuable data structures (List, Set, Map, Queue, ...), generics offer type safety with regard to using the collections in the right manner. Plus, Java Stream APIs provide convenient and flexible ways to operate on elements in collections. That's why you will learn Java collections and generics together, and use Java Stream APIs for processing data in the collections.
1. Getting started with Java Collections & Generics for beginners:
If you're new to Java Collections framework and Generics, check these articles first. You will understand the key concepts and overview of how collections and generics are designed in the Java programming language.
- What is Java Collections Framework?
- Java Collections Framework summary table
- What are Generics in Java
- How to write generic classes and methods in Java
2. Java List Tutorials:
Use Lists to store elements that will be accessed via index, and duplicate elements allowed. Elements are usually stored in the order they added into a List.
- Java List Collection Tutorial and Examples
- Sorting List Collections Examples
- Sorting a list by multiple attributes example
- Java Collections Utility Examples for Changing Order and Content of a List
3. Java Set Tutorials:
Sets are used when the order of elements does not matter and no duplicate elements allowed.
- Java Set Collection Tutorial and Examples
- Java SortedSet and TreeSet Tutorial and Examples
- Java NavigableSet and TreeSet Tutorial and Examples
4. Java Map Tutorials:
Maps are used when you need a key-value mapping data structure.
- Java Map Collection Tutorial and Examples
- Java NavigableMap and TreeMap Tutorial and Examples
- Java SortedMap and TreeMap Tutorial and Examples
5. Java Queue Tutorials:
You use Queues in producer-consumer processing, i.e. holding elements prior to processing and remove elements afterward.
6. Java Arrays Tutorials:
Check the follow articles to learn more about using arrays in the Java programming language, as well as conversion from arrays to collections.
- Comparing Arrays in Java Examples
- Copying and Filling Arrays in Java
- Java Arrays Utility Class Examples for List view, Sorting and Searching
- Sorting Arrays Examples (with Comparable and Comparator)
7. Java Collection Iteration Tutorials:
Learn how to iterate over elements in collections properly
- Java Collections Looping Example
- Using Java Lambda expressions for collections internal iteration
- 5 Ways to Iterate Collections in Java
8. Java Streams Tutorials:
Learn how Java Stream APIs can simplify operations on elements in a collection.
- Understanding Java Stream API
- Java Stream Aggregate Functions Examples (Intermediate Operations)
- Java Stream Terminal Operations Examples
9. Advanced Java Collections Tutorials:
It's recommended to get familiar with advanced concepts like equals, hashCode, object ordering, comparator, etc to use Java collections more efficiently
- Understanding equals() and hashCode() in Java
- Understanding Object Ordering in Java with Comparable and Comparator
- Understanding Collections and Thread Safety in Java
- 18 Java Collections and Generics Best Practices
10. Advanced Java Generics Tutorials:
These articles help you understand advanced concepts in Java Generics:
- Generics with extends and super Wildcards and the Get and Put Principle
- Generics with Subtyping and the Substitution Principle
11. Miscellaneous Java Collection Tutorials:
Learn how to use the utility classes for common operations on collections, so you won't re-invent the wheel.
- Java Collections Factory Method Examples
- Java Collections Wrapper Methods Examples
- Java Collections Utility Examples for Searching in a Collection
Following these tutorials is enough to get familiar with Java collections and use the APIs in your daily coding. If you want to learn deeper, I recommend you check the Java Generics and Collections book that covers everything from most basic uses to the strangest corner cases.