PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Collections in Java

← All stacks

Theory

194/270

Collections in Java

The Collections Framework gives ready-made structures for groups of objects. List: ordered, duplicates allowed — ArrayList. Set: unique elements — HashSet. Map: key → value — HashMap (Map is separate but part of the same story).

Prefer generics: List<String> so types stay safe. Pick by need: fast index get → ArrayList; uniqueness → HashSet; key lookup → HashMap. Don’t use a raw array for everything that must grow or shrink.

Draw List vs Set vs Map in ten seconds with one property each.

Let's take this on the board with one tiny Main class — no extra files. Collections in Java — output: 3. Three real names: Asha, Ravi, Neha. size() is 3. Start from main, go line by line, and stop at each print. That output is the proof for Collections.

Diagram
List  → order + duplicates   (ArrayList)
  Set   → unique only          (HashSet)
  Map   → key → value          (HashMap)
Exam tip

List / Set / Map — one line each.

Example

import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    ArrayList<String> names = new ArrayList<>();
    names.add("Asha");
    names.add("Ravi");
    names.add("Neha");
    System.out.println(names.size()); // 3
  }
}

Collections in Java — output: 3. Three real names: Asha, Ravi, Neha. size() is 3.

Short notes

  • DefCollections Framework = ready-made structures for groups of objects.
  • RuleList = ordered + duplicates OK. Set = unique. Map = key → value.
  • RememberUse generics: List<String>.
  • UseArrayList for index, HashSet for unique, HashMap for lookup.

Questions

1

List vs Set?

2

What is a Map?

3

Why generics?

Previous← Call private methodNextJava ArrayList →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.