Data Types and Operators
(Non-Primitive Data Types)
Control Flow Statements
Conditional Statements
Looping Statements
Branching Statements
Object-Oriented Programming (OOP)
Exception Handling
Collections Framework
Overview of Collections
Java I/O
Multithreading
GUI Programming with Swing
Advanced Topics
JAVA CODE
Java Basics
Working with Objects
Arrays, Conditionals, and Loops
Creating Classes and Applications in Java
More About Methods
Java Applet Basics
Graphics, Fonts, and Color
Simple Animation and Threads
More Animation, Images, and Sound
Managing Simple Events and Interactivity
Creating User Interfaces with the awt
Windows, Networking, and Other Tidbits
Modifiers, Access Control, and Class Design
Packages and Interfaces
Exceptions
Multithreading
Streams and I/O
Using Native Methods and Libraries
Under the Hood
Java Programming Tools
Working with Data Structures in Java
Advanced Animation and Media
Fun with Image Filters
Client/Server Networking in Java
Emerging Technologies
appendix A :- Language Summary
appendix B :- Class Hierarchy Diagrams
appendix C The Java Class Library
appendix D Bytecodes Reference
appendix E java.applet Package Reference
appendix F java.awt Package Reference
appendix G java.awt.image Package Reference
appendix H java.awt.peer Package Reference
appendix I java.io Package Reference
appendix J java.lang Package Reference
appendix K java.net Package Reference
appendix L java.util Package Reference

Here is explain each of these Java collections with examples to illustrate their usage. These collections are part of the Java Collections Framework, which provides a standardized way to manipulate groups of objects

ArrayList

ArrayList is a resizable array implementation of the List interface. It allows duplicate elements and maintains insertion order.

Example:

				
					import java.util.ArrayList;

public class ArrayListExample {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Apple");
        list.add("Banana");
        list.add("Orange");

        for (String fruit : list) {
            System.out.println(fruit);
        }
    }
}

				
			

Output:

				
					Apple
Banana
Orange

				
			

ArrayList

LinkedList‘ is a doubly linked list implementation of the List and Deque interfaces. It also allows duplicate elements and maintains insertion order.

Example:

				
					import java.util.LinkedList;

public class LinkedListExample {
    public static void main(String[] args) {
        LinkedList<String> list = new LinkedList<>();
        list.add("Apple");
        list.add("Banana");
        list.add("Orange");

        for (String fruit : list) {
            System.out.println(fruit);
        }
    }
}

				
			

Output:

				
					Apple
Banana
Orange

				
			

HashSet

HashSet‘ is an implementation of the ‘Set‘ interface that uses a hash table. It does not allow duplicate elements and does not maintain any order.

Example:

				
					import java.util.HashSet;

public class HashSetExample {
    public static void main(String[] args) {
        HashSet<String> set = new HashSet<>();
        set.add("Apple");
        set.add("Banana");
        set.add("Orange");
        set.add("Apple");  // Duplicate element, will not be added

        for (String fruit : set) {
            System.out.println(fruit);
        }
    }
}

				
			

Output:

				
					Banana
Apple
Orange

				
			

TreeSet

TreeSet‘ is an implementation of the Set interface that uses a tree for storage. It orders its elements based on their values (natural ordering or a specified comparator).

Example:

				
					import java.util.TreeSet;

public class TreeSetExample {
    public static void main(String[] args) {
        TreeSet<String> set = new TreeSet<>();
        set.add("Apple");
        set.add("Banana");
        set.add("Orange");

        for (String fruit : set) {
            System.out.println(fruit);
        }
    }
}

				
			

Output:

				
					Apple
Banana
Orange

				
			

HashMap

HashMap‘ is an implementation of the ‘Map‘ interface that uses a hash table. It allows null values and one null key. It does not maintain any order.

Example:

				
					import java.util.HashMap;

public class HashMapExample {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("Apple", 1);
        map.put("Banana", 2);
        map.put("Orange", 3);

        for (String key : map.keySet()) {
            System.out.println(key + ": " + map.get(key));
        }
    }
}

				
			

Output:

				
					Apple: 1
Banana: 2
Orange: 3

				
			

TreeMap

TreeMap‘ is an implementation of the ‘Map‘ interface that uses a red-black tree. It orders its keys based on their values (natural ordering or a specified comparator).

Example:

				
					import java.util.TreeMap;

public class TreeMapExample {
    public static void main(String[] args) {
        TreeMap<String, Integer> map = new TreeMap<>();
        map.put("Apple", 1);
        map.put("Banana", 2);
        map.put("Orange", 3);

        for (String key : map.keySet()) {
            System.out.println(key + ": " + map.get(key));
        }
    }
}

				
			

Output:

				
					Apple: 1
Banana: 2
Orange: 3

				
			
Scroll to Top