Java Lesson 40 – Collections Project | Dataplexa

Collections Mini Project

In this lesson, we will build a small but realistic Java application using Collections.

Instead of learning theory, we will apply Lists, Maps, Iterators, Sorting, and Algorithms together — exactly how Java is used in real projects.


Project Overview

We will build a simple Student Management System that:

  • Stores student records
  • Uses Collections to manage data
  • Sorts students based on marks
  • Finds top and lowest performers

This project mirrors how backend systems manage in-memory data.


Student Data Model

First, we create a Student class. Each student has an ID, name, and marks.


class Student {
    int id;
    String name;
    int marks;

    Student(int id, String name, int marks) {
        this.id = id;
        this.name = name;
        this.marks = marks;
    }
}

Storing Students Using List

We use an ArrayList to store student objects.


import java.util.ArrayList;
import java.util.List;

List students = new ArrayList<>();

students.add(new Student(101, "Alice", 85));
students.add(new Student(102, "Bob", 72));
students.add(new Student(103, "Charlie", 90));
students.add(new Student(104, "Diana", 65));

Using a List allows dynamic growth and easy iteration.


Displaying Student Records

Let us print all student details.


for (Student s : students) {
    System.out.println(s.id + " " + s.name + " " + s.marks);
}

Sorting Students by Marks

We now sort students based on marks using a Comparator.


import java.util.Collections;

Collections.sort(students, (s1, s2) -> s2.marks - s1.marks);

This sorts students in descending order (highest marks first).


Finding Top and Lowest Scorers

Once sorted, finding results becomes easy.


Student topper = students.get(0);
Student lowest = students.get(students.size() - 1);

System.out.println("Topper: " + topper.name + " - " + topper.marks);
System.out.println("Lowest: " + lowest.name + " - " + lowest.marks);

Removing Failed Students Using Iterator

Now we remove students who scored below 70 using an Iterator.


import java.util.Iterator;

Iterator it = students.iterator();

while (it.hasNext()) {
    if (it.next().marks < 70) {
        it.remove();
    }
}

Iterator ensures safe removal during traversal.


Final Output

After filtering, let us print the updated list.


for (Student s : students) {
    System.out.println(s.name + " passed with " + s.marks);
}

What This Project Teaches

  • How collections work together in real programs
  • Why sorting and iterators are important
  • How data flows through Java applications
  • How small logic builds larger systems

Industry Connection

This same pattern is used in:

  • Student portals
  • Employee management systems
  • Backend APIs before database storage
  • Data preprocessing layers

Key Takeaways

  • Collections simplify data management
  • Mini projects connect theory to practice
  • Java collections are core to enterprise apps

In the next lesson, we move into Advanced Java and start with Exception Handling.