0% found this document useful (0 votes)
5 views4 pages

Module - Array List in Java

This module introduces ArrayList in Java, explaining its definition, features, and usage for dynamic data storage and manipulation. It covers key differences between ArrayLists and arrays, common methods, and advantages and limitations. By the end, learners will be able to define ArrayList, use its methods, and perform basic operations.

Uploaded by

tongquin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Module - Array List in Java

This module introduces ArrayList in Java, explaining its definition, features, and usage for dynamic data storage and manipulation. It covers key differences between ArrayLists and arrays, common methods, and advantages and limitations. By the end, learners will be able to define ArrayList, use its methods, and perform basic operations.

Uploaded by

tongquin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Learning Module: ArrayList in Java

Overview
This module introduces ArrayList in Java, a part of the Java Collections Framework. It explains what an
ArrayList is, how it works, and how it is used to store and manipulate dynamic data. This module is designed
for beginners who already have basic knowledge of Java variables and data types.

Learning Objectives
By the end of this module, learners should be able to: - Define ArrayList in Java - Differentiate ArrayList from
arrays - Use common ArrayList methods - Perform basic operations using ArrayList

Lesson 1: What is an ArrayList?

Definition

An ArrayList is a resizable array implementation of the List interface in Java. Unlike arrays, ArrayLists
can grow or shrink dynamically.

Key Features

• Dynamic size
• Allows duplicate elements
• Maintains insertion order
• Stores objects (not primitive types directly)

Lesson 2: ArrayList vs Array

Feature Array ArrayList

Size Fixed Dynamic

Data Type Can store primitives Stores objects only

Flexibility Limited More flexible

Methods Few Many built-in methods

1
Lesson 3: Declaring and Creating an ArrayList

Syntax

ArrayList<Type> listName = new ArrayList<Type>();

Example

ArrayList<String> names = new ArrayList<String>();

Lesson 4: Common ArrayList Methods


• add() – Adds an element
• get() – Retrieves an element
• set() – Updates an element
• remove() – Removes an element
• size() – Returns number of elements
• clear() – Removes all elements

Example

[Link]("Anna");
[Link]("John");
[Link]([Link](0));

Lesson 5: Iterating Through an ArrayList

Using a for-loop

for(int i = 0; i < [Link](); i++) {


[Link]([Link](i));
}

2
Using enhanced for-loop

for(String name : names) {


[Link](name);
}

Lesson 6: Advantages and Limitations

Advantages

• Easy to use
• Automatically resizes
• Provides many useful methods

Limitations

• Slower than arrays for some operations


• Uses more memory
• Cannot store primitive data types directly

Learning Activities
Activity 1: Create an ArrayList of integers and add five values.

Activity 2: Write a program to display all elements in an ArrayList.

Assessment (Short Quiz)


1. What is an ArrayList?
2. Give two differences between an array and an ArrayList.
3. Name three ArrayList methods.

Summary
• ArrayList is a dynamic data structure in Java
• It is part of the Java Collections Framework
• It provides flexible methods for data manipulation
• Commonly used for storing and managing lists of objects

3
References
• Java Documentation (Oracle)
• Java Programming textbooks

You might also like