Fiveable
Fiveable
pep
Fiveable
Fiveable

or

Log in

Find what you need to study


Light

Unit 7 Overview: ArrayList

10 min readjanuary 10, 2023

Kashvi Panjolia

Kashvi Panjolia

Kashvi Panjolia

Kashvi Panjolia

The Big Takeaway of this Unit

Exam Weighting

  • 2.5-7.5% of the test

  • Roughly 1 to 2 multiple-choice questions

  • A possible topic of FRQ #3, which may test your ability to make ArrayLists and ArrayList algorithms.

Enduring Understanding

We will now move on to the next data structure in this course, the ArrayList. Unlike the array, ArrayLists don't have a fixed size, and we can add and remove items from them. ArrayLists are part of the Java Collections Framework, which contains different data structures for different purposes. If you decide to learn more about Java in a second course, you will learn all about these data structures!

Building Computational Thinking

ArrayLists are more versatile than arrays in many situations, but there are different methods that must be used to achieve this. Thus, it is important to know the difference between arrays and ArrayLists. Using ArrayLists, we will also learn how to sort and search elements, which are two of the most important applications.

Main Ideas for this Unit

7.1 Introduction to ArrayList

An ArrayList is a data structure that allows you to store a collection of items in an ordered list. It is similar to an array, but it is dynamic in size, which means you can add or remove items from the list without having to specify the size of the list beforehand.

One of the key features of an ArrayList is its mutability. This means that the elements in the list can be changed after the list is created. For example, you can add or remove elements from the list, or you can change the value of an element at a specific index in the list.

To create an ArrayList, you can use the ArrayList constructor, which takes no arguments:

ArrayList<E> list = new ArrayList<>();

You can also create an ArrayList with a specific initial capacity:

ArrayList<E> list = new ArrayList<>(int initialCapacity);

The generic type E specifies the type of elements that will be stored in the ArrayList. For example, if you want to create an ArrayList that holds integers, you would use the type Integer like this:

ArrayList<Integer> list = new ArrayList<>();

It is important to note that ArrayLists can only store objects, not primitive types (int, boolean, double). This is where the wrapper classes you learned about in Unit 2 come in! In order to add a primitive type to an ArrayList, you must first wrap the primitive type in its wrapper class to turn it into an object.

7.2 ArrayList Methods

The ArrayList class is not part of the standard Java package, so it must be imported into your class so you can use it. This is the import statement you need to write:

import java.util.ArrayList;

Unlike arrays, the ArrayList uses methods to add, remove, and manipulate the list. This is a list of all the methods you need to know to be proficient with ArrayLists for the AP exam:

  • int size() -- Returns an integer with the number of elements currently in the list

  • boolean add(E obj) -- Appends (adds to the end) obj to the end of the list; returns true if added and false if not

  • void add(int index, E obj): This method is used to add an element to the ArrayList at a specified index. The first parameter, index, is the position in the list where the element will be added, and the second parameter, obj, is the element that you want to add to the list. If the index is equal to the size of the list, the element is added at the end of the list. If the index is less than the size of the list, the element is inserted at the specified index, and any elements that were previously at that index or later are shifted one position to the right.

  • E get(int index): Used to retrieve an element from the ArrayList at a specified index. The parameter, index, is the position in the list of the element that you want to retrieve. The method returns the element at the specified index, or null if the index is out of bounds.

  • E set(int index, E obj): This method updates an element in the ArrayList at a specified index. The first parameter, index, is the position in the list of the element that you want to update, and the second parameter, obj, is the new value of the element. The method returns the element that was previously at the specified index. It throws an exception if the index is out of bounds.

  • E remove(int index): This method is used to remove an element from the ArrayList at a specified index. The parameter, index, is the position in the list of the element that you want to remove. The method returns the element that was removed, or null if the index is out of bounds.

7.3 Traversing ArrayLists

The indices of an ArrayList start at 0 and end at size() - 1, so make sure your code only runs within these indices or you will get an IndexOutOfBoundsException.

Like arrays, you can use a for or while loop and an enhanced for loop (for-each loop) to traverse an ArrayList. This is how to traverse an ArrayList using a for loop:

ArrayList<Integer> list = new ArrayList<>();

list.add(1);

list.add(2);

list.add(3);

for (int i = 0; i < list.size(); i++) {

System.out.println(list.get(i));

}

This for loop creates the variable i to store the index of the elements, then uses those indices to access the elements, much like traversing an array. Notice, however, that the get method of the ArrayList is used to retrieve the elements, and that instead of array.length, we are using list.size() to determine the length of the list.

Using an enhanced for loop to traverse through the ArrayList is also possible:

for (Integer number : list) {

System.out.println(number);

}

A ConcurrentModificationException can be thrown if you change the size of the ArrayList while you are using a for-each loop to traverse it. Remember that for-each loops cannot modify the original data structure, so if you try to add or remove elements of an ArrayList with a for-each loop, this exception will be thrown.

7.4 Developing Algorithms Using ArrayLists

ArrayLists have their own versions of the standard algorithms you learned in the last unit with arrays. You need to know how to:

  • Insert an element in the ArrayList

  • Delete an element

  • Turn arrays into ArrayLists and vice versa

  • Perform all the standard array algorithms mentioned in the Unit 6 Overview

The code below explains how to turn an ArrayList into an array:

ArrayList<Integer> list = new ArrayList<>();

list.add(1);

list.add(2);

list.add(3);

Integer[] array = new Integer[list.size()];

for (int i = 0; i < list.size(); i++) {

array[i] = list.get(i);

}

In this example, a new Integer array is created with the same size as the ArrayList. A for loop is used to iterate through the elements of the ArrayList, and the elements are added to the array one by one using the array's index, which is stored in the variable i.

7.5 Searching

Linear search, also known as sequential search, is a method for searching an ArrayList for a specific value. The algorithm iterates through the array or list, one element at a time, from the start to the end, until it finds the target element or determines that the element is not present.

You can implement linear search for an ArrayList using a for loop. You would start by iterating through the elements of the ArrayList, one at a time, using the for loop. At each iteration, you would check if the current element is equal to the target element. If it is, you would return the index of that element. If the for loop completes without finding the target element, you would return -1 to indicate that the element was not found.

Linear search is very similar to traversing an ArrayList:

public int linearSearch(ArrayList<Integer> list, int target) {

for (int i = 0; i < list.size(); i++) {

if (list.get(i) == target) {

return i;

}

}

return -1;

}

This function takes an ArrayList of integers and a target integer as input, and returns the index of the target element in the list, or -1 if the element is not found.

7.6 Sorting

Selection sort and insertion sort are two commonly-used sorting algorithms in computer science. Both algorithms can be used to sort an array or an ArrayList.

Selection sort works by repeatedly finding the minimum element from the unsorted portion of the array or list, and then moving it to the sorted portion of the array or list. The algorithm repeatedly selects the smallest element from the unsorted portion of the array and then swaps it with the first element of the unsorted portion. This process is repeated for the remaining unsorted portion of the array or list, which results in the entire array or list being sorted.

Take some time to trace through this code for a selection sort using an ArrayList to build your understanding.

public void selectionSort(ArrayList<Integer> list) {

for (int i = 0; i < list.size(); i++) {

int minIndex = i;

for (int j = i + 1; j < list.size(); j++) {

if (list.get(j) < list.get(minIndex)) {

minIndex = j;

}

}

int temp = list.get(i);

list.set(i, list.get(minIndex));

list.set(minIndex, temp);

}

}

https://i.makeagif.com/media/1-24-2016/VrJ-Br.gif

A visual explanation of how selection sort works. GIF courtesy of Make a GIF.

On the other hand, Insertion Sort starts by assuming that the first element of the ArrayList is already sorted, and then it picks the next element and insert it into the correct position in the already sorted portion of the array. The algorithm repeatedly compares an unsorted element with the sorted elements to the left of it, and then shifts the sorted elements to the right to make room for the unsorted element to be inserted into its correct position.

This is the Insertion Sort implemented on a generic ArrayList:

public void insertionSort(ArrayList<Integer> list) {

for (int i = 1; i < list.size(); i++) {

int current = list.get(i);

int j = i - 1;

while (j >= 0 && list.get(j) > current) {

list.set(j + 1, list.get(j));

j--;

}

list.set(j + 1, current);

}

}

https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif?20110419160033

A visual explanation of insertion sort. GIF courtesy of Wikimedia.

7.7 Ethical Issues Around Data Collection

The ethical issues around data collection arise from the collection, storage, and use of personal data by companies, organizations, and governments. The sheer volume of data that is being collected, combined with advances in technology that make it easier to store and analyze data, has led to concerns about the potential for misuse of personal data, such as privacy violations and erosions of civil liberties.

As a programmer, there are several steps you can take to safeguard your users' personal privacy:

  • Use encryption when handling personal data: Encryption is the process of converting plain text into a code to protect the data from unauthorized access. 🔐

  • Be careful about what data you collect: only collect the data that is truly necessary for your application, and consider the potential risks associated with each type of data.

  • Implement security measures like firewalls, intrusion detection and prevention systems, and authentication and access controls, to protect personal data from unauthorized access or theft.

  • Be transparent with users about data collection and usage: Be upfront with users about what data you are collecting, why you are collecting it, and how you plan to use it. This helps to build trust with users and also help them to make more informed decisions about the data they share. 🤝

Key Terms to Review (26)

add(E obj)

: The add(E obj) method is used to insert an element into a collection such as an ArrayList or LinkedList.

add(int index, E obj)

: This method is used to insert an element at a specific index in an ArrayList. It shifts the existing elements to the right and increases the size of the ArrayList by one.

Algorithms

: Algorithms are step-by-step procedures or instructions for solving problems or performing tasks. They provide clear instructions on how to solve problems efficiently.

ArrayList

: ArrayList is a dynamic data structure that allows you to store and manipulate collections of objects. Unlike arrays, ArrayLists can grow or shrink dynamically as needed.

ArrayList Algorithms

: ArrayList Algorithms refer to the various methods and operations that can be performed on an ArrayList, which is a dynamic array-like data structure in Java. These algorithms allow for efficient manipulation, retrieval, and modification of elements stored in an ArrayList.

ArrayList constructor

: The ArrayList constructor is a special method that creates an instance of the ArrayList class. It allows you to initialize an ArrayList object with specific elements or specify its initial capacity.

ArrayList Methods

: ArrayList methods are built-in functions that allow us to manipulate and work with ArrayLists, which are dynamic arrays that can grow or shrink in size.

Arrays

: Arrays are a collection of elements of the same data type, stored in contiguous memory locations. They have a fixed size and can be accessed using an index.

Authentication and Access Controls

: Authentication and access controls refer to the processes and mechanisms used to verify the identity of users and regulate their access to computer systems or resources.

ConcurrentModificationException

: A ConcurrentModificationException occurs when a collection is modified while being iterated over using an iterator or enhanced for loop.

Data Structure

: A data structure is a way of organizing and storing data in a computer so that it can be accessed and used efficiently. It provides a systematic way to manage and manipulate data.

Delete element from ArrayList

: Deleting an element from an ArrayList refers to the process of removing a specific item from the list, causing the remaining elements to shift down and fill the empty space.

Encryption

: Encryption is the process of converting plain text into a secret code to protect sensitive information from unauthorized access.

Enhanced For Loop (For-each Loop)

: The enhanced for loop (or for-each loop) is a simplified loop structure introduced in Java that allows easy iteration over arrays or collections without explicitly managing an index or iterator.

Firewalls

: Firewalls are security systems that monitor and control incoming and outgoing network traffic based on predetermined security rules, protecting networks from unauthorized access or malicious activities.

Import Statement

: An import statement in Java is used to bring classes or packages from other libraries into your current program. It allows you to use those classes or packages without having to fully qualify their names.

Initial capacity

: Initial capacity refers to the starting size or capacity allocated for an ArrayList when it is created using its constructor. It determines how many elements can be stored in the list before it needs to dynamically resize itself.

Insert element in ArrayList

: Inserting an element in an ArrayList refers to adding a new element at a specific position within the ArrayList. This operation shifts existing elements to accommodate the new element and maintains the order of the remaining elements.

Insertion Sort

: Insertion sort is a simple sorting algorithm where each iteration removes one element from an input data set and inserts it into its correct position within a partially sorted list until all elements are inserted.

Intrusion Detection Systems

: Intrusion Detection Systems (IDS) are security tools designed to detect unauthorized access attempts or suspicious activities within computer networks or systems.

Java Collections Framework

: The Java Collections Framework is a set of classes and interfaces in Java that provide implementations of common data structures like lists, sets, and maps. It offers a unified interface for working with collections of objects.

Linear Search

: Linear search is a simple searching algorithm that sequentially checks each element in a list until it finds the target value or reaches the end of the list.

Selection Sort

: Selection Sort is a simple sorting algorithm that repeatedly finds the minimum element from an unsorted portion of the list and swaps it with the first element of that portion until the entire list is sorted.

size()

: The size() method is used to determine the total number of elements present in a collection, such as a list or array.

Traversing ArrayLists

: Traversing ArrayLists refers to the process of accessing and examining each element in an ArrayList. It involves iterating through the elements sequentially, usually using a loop.

Wrapper Classes

: Wrapper classes are classes in Java that provide a way to wrap primitive data types into objects. They allow us to perform operations on primitives as if they were objects.

Unit 7 Overview: ArrayList

10 min readjanuary 10, 2023

Kashvi Panjolia

Kashvi Panjolia

Kashvi Panjolia

Kashvi Panjolia

The Big Takeaway of this Unit

Exam Weighting

  • 2.5-7.5% of the test

  • Roughly 1 to 2 multiple-choice questions

  • A possible topic of FRQ #3, which may test your ability to make ArrayLists and ArrayList algorithms.

Enduring Understanding

We will now move on to the next data structure in this course, the ArrayList. Unlike the array, ArrayLists don't have a fixed size, and we can add and remove items from them. ArrayLists are part of the Java Collections Framework, which contains different data structures for different purposes. If you decide to learn more about Java in a second course, you will learn all about these data structures!

Building Computational Thinking

ArrayLists are more versatile than arrays in many situations, but there are different methods that must be used to achieve this. Thus, it is important to know the difference between arrays and ArrayLists. Using ArrayLists, we will also learn how to sort and search elements, which are two of the most important applications.

Main Ideas for this Unit

7.1 Introduction to ArrayList

An ArrayList is a data structure that allows you to store a collection of items in an ordered list. It is similar to an array, but it is dynamic in size, which means you can add or remove items from the list without having to specify the size of the list beforehand.

One of the key features of an ArrayList is its mutability. This means that the elements in the list can be changed after the list is created. For example, you can add or remove elements from the list, or you can change the value of an element at a specific index in the list.

To create an ArrayList, you can use the ArrayList constructor, which takes no arguments:

ArrayList<E> list = new ArrayList<>();

You can also create an ArrayList with a specific initial capacity:

ArrayList<E> list = new ArrayList<>(int initialCapacity);

The generic type E specifies the type of elements that will be stored in the ArrayList. For example, if you want to create an ArrayList that holds integers, you would use the type Integer like this:

ArrayList<Integer> list = new ArrayList<>();

It is important to note that ArrayLists can only store objects, not primitive types (int, boolean, double). This is where the wrapper classes you learned about in Unit 2 come in! In order to add a primitive type to an ArrayList, you must first wrap the primitive type in its wrapper class to turn it into an object.

7.2 ArrayList Methods

The ArrayList class is not part of the standard Java package, so it must be imported into your class so you can use it. This is the import statement you need to write:

import java.util.ArrayList;

Unlike arrays, the ArrayList uses methods to add, remove, and manipulate the list. This is a list of all the methods you need to know to be proficient with ArrayLists for the AP exam:

  • int size() -- Returns an integer with the number of elements currently in the list

  • boolean add(E obj) -- Appends (adds to the end) obj to the end of the list; returns true if added and false if not

  • void add(int index, E obj): This method is used to add an element to the ArrayList at a specified index. The first parameter, index, is the position in the list where the element will be added, and the second parameter, obj, is the element that you want to add to the list. If the index is equal to the size of the list, the element is added at the end of the list. If the index is less than the size of the list, the element is inserted at the specified index, and any elements that were previously at that index or later are shifted one position to the right.

  • E get(int index): Used to retrieve an element from the ArrayList at a specified index. The parameter, index, is the position in the list of the element that you want to retrieve. The method returns the element at the specified index, or null if the index is out of bounds.

  • E set(int index, E obj): This method updates an element in the ArrayList at a specified index. The first parameter, index, is the position in the list of the element that you want to update, and the second parameter, obj, is the new value of the element. The method returns the element that was previously at the specified index. It throws an exception if the index is out of bounds.

  • E remove(int index): This method is used to remove an element from the ArrayList at a specified index. The parameter, index, is the position in the list of the element that you want to remove. The method returns the element that was removed, or null if the index is out of bounds.

7.3 Traversing ArrayLists

The indices of an ArrayList start at 0 and end at size() - 1, so make sure your code only runs within these indices or you will get an IndexOutOfBoundsException.

Like arrays, you can use a for or while loop and an enhanced for loop (for-each loop) to traverse an ArrayList. This is how to traverse an ArrayList using a for loop:

ArrayList<Integer> list = new ArrayList<>();

list.add(1);

list.add(2);

list.add(3);

for (int i = 0; i < list.size(); i++) {

System.out.println(list.get(i));

}

This for loop creates the variable i to store the index of the elements, then uses those indices to access the elements, much like traversing an array. Notice, however, that the get method of the ArrayList is used to retrieve the elements, and that instead of array.length, we are using list.size() to determine the length of the list.

Using an enhanced for loop to traverse through the ArrayList is also possible:

for (Integer number : list) {

System.out.println(number);

}

A ConcurrentModificationException can be thrown if you change the size of the ArrayList while you are using a for-each loop to traverse it. Remember that for-each loops cannot modify the original data structure, so if you try to add or remove elements of an ArrayList with a for-each loop, this exception will be thrown.

7.4 Developing Algorithms Using ArrayLists

ArrayLists have their own versions of the standard algorithms you learned in the last unit with arrays. You need to know how to:

  • Insert an element in the ArrayList

  • Delete an element

  • Turn arrays into ArrayLists and vice versa

  • Perform all the standard array algorithms mentioned in the Unit 6 Overview

The code below explains how to turn an ArrayList into an array:

ArrayList<Integer> list = new ArrayList<>();

list.add(1);

list.add(2);

list.add(3);

Integer[] array = new Integer[list.size()];

for (int i = 0; i < list.size(); i++) {

array[i] = list.get(i);

}

In this example, a new Integer array is created with the same size as the ArrayList. A for loop is used to iterate through the elements of the ArrayList, and the elements are added to the array one by one using the array's index, which is stored in the variable i.

7.5 Searching

Linear search, also known as sequential search, is a method for searching an ArrayList for a specific value. The algorithm iterates through the array or list, one element at a time, from the start to the end, until it finds the target element or determines that the element is not present.

You can implement linear search for an ArrayList using a for loop. You would start by iterating through the elements of the ArrayList, one at a time, using the for loop. At each iteration, you would check if the current element is equal to the target element. If it is, you would return the index of that element. If the for loop completes without finding the target element, you would return -1 to indicate that the element was not found.

Linear search is very similar to traversing an ArrayList:

public int linearSearch(ArrayList<Integer> list, int target) {

for (int i = 0; i < list.size(); i++) {

if (list.get(i) == target) {

return i;

}

}

return -1;

}

This function takes an ArrayList of integers and a target integer as input, and returns the index of the target element in the list, or -1 if the element is not found.

7.6 Sorting

Selection sort and insertion sort are two commonly-used sorting algorithms in computer science. Both algorithms can be used to sort an array or an ArrayList.

Selection sort works by repeatedly finding the minimum element from the unsorted portion of the array or list, and then moving it to the sorted portion of the array or list. The algorithm repeatedly selects the smallest element from the unsorted portion of the array and then swaps it with the first element of the unsorted portion. This process is repeated for the remaining unsorted portion of the array or list, which results in the entire array or list being sorted.

Take some time to trace through this code for a selection sort using an ArrayList to build your understanding.

public void selectionSort(ArrayList<Integer> list) {

for (int i = 0; i < list.size(); i++) {

int minIndex = i;

for (int j = i + 1; j < list.size(); j++) {

if (list.get(j) < list.get(minIndex)) {

minIndex = j;

}

}

int temp = list.get(i);

list.set(i, list.get(minIndex));

list.set(minIndex, temp);

}

}

https://i.makeagif.com/media/1-24-2016/VrJ-Br.gif

A visual explanation of how selection sort works. GIF courtesy of Make a GIF.

On the other hand, Insertion Sort starts by assuming that the first element of the ArrayList is already sorted, and then it picks the next element and insert it into the correct position in the already sorted portion of the array. The algorithm repeatedly compares an unsorted element with the sorted elements to the left of it, and then shifts the sorted elements to the right to make room for the unsorted element to be inserted into its correct position.

This is the Insertion Sort implemented on a generic ArrayList:

public void insertionSort(ArrayList<Integer> list) {

for (int i = 1; i < list.size(); i++) {

int current = list.get(i);

int j = i - 1;

while (j >= 0 && list.get(j) > current) {

list.set(j + 1, list.get(j));

j--;

}

list.set(j + 1, current);

}

}

https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif?20110419160033

A visual explanation of insertion sort. GIF courtesy of Wikimedia.

7.7 Ethical Issues Around Data Collection

The ethical issues around data collection arise from the collection, storage, and use of personal data by companies, organizations, and governments. The sheer volume of data that is being collected, combined with advances in technology that make it easier to store and analyze data, has led to concerns about the potential for misuse of personal data, such as privacy violations and erosions of civil liberties.

As a programmer, there are several steps you can take to safeguard your users' personal privacy:

  • Use encryption when handling personal data: Encryption is the process of converting plain text into a code to protect the data from unauthorized access. 🔐

  • Be careful about what data you collect: only collect the data that is truly necessary for your application, and consider the potential risks associated with each type of data.

  • Implement security measures like firewalls, intrusion detection and prevention systems, and authentication and access controls, to protect personal data from unauthorized access or theft.

  • Be transparent with users about data collection and usage: Be upfront with users about what data you are collecting, why you are collecting it, and how you plan to use it. This helps to build trust with users and also help them to make more informed decisions about the data they share. 🤝

Key Terms to Review (26)

add(E obj)

: The add(E obj) method is used to insert an element into a collection such as an ArrayList or LinkedList.

add(int index, E obj)

: This method is used to insert an element at a specific index in an ArrayList. It shifts the existing elements to the right and increases the size of the ArrayList by one.

Algorithms

: Algorithms are step-by-step procedures or instructions for solving problems or performing tasks. They provide clear instructions on how to solve problems efficiently.

ArrayList

: ArrayList is a dynamic data structure that allows you to store and manipulate collections of objects. Unlike arrays, ArrayLists can grow or shrink dynamically as needed.

ArrayList Algorithms

: ArrayList Algorithms refer to the various methods and operations that can be performed on an ArrayList, which is a dynamic array-like data structure in Java. These algorithms allow for efficient manipulation, retrieval, and modification of elements stored in an ArrayList.

ArrayList constructor

: The ArrayList constructor is a special method that creates an instance of the ArrayList class. It allows you to initialize an ArrayList object with specific elements or specify its initial capacity.

ArrayList Methods

: ArrayList methods are built-in functions that allow us to manipulate and work with ArrayLists, which are dynamic arrays that can grow or shrink in size.

Arrays

: Arrays are a collection of elements of the same data type, stored in contiguous memory locations. They have a fixed size and can be accessed using an index.

Authentication and Access Controls

: Authentication and access controls refer to the processes and mechanisms used to verify the identity of users and regulate their access to computer systems or resources.

ConcurrentModificationException

: A ConcurrentModificationException occurs when a collection is modified while being iterated over using an iterator or enhanced for loop.

Data Structure

: A data structure is a way of organizing and storing data in a computer so that it can be accessed and used efficiently. It provides a systematic way to manage and manipulate data.

Delete element from ArrayList

: Deleting an element from an ArrayList refers to the process of removing a specific item from the list, causing the remaining elements to shift down and fill the empty space.

Encryption

: Encryption is the process of converting plain text into a secret code to protect sensitive information from unauthorized access.

Enhanced For Loop (For-each Loop)

: The enhanced for loop (or for-each loop) is a simplified loop structure introduced in Java that allows easy iteration over arrays or collections without explicitly managing an index or iterator.

Firewalls

: Firewalls are security systems that monitor and control incoming and outgoing network traffic based on predetermined security rules, protecting networks from unauthorized access or malicious activities.

Import Statement

: An import statement in Java is used to bring classes or packages from other libraries into your current program. It allows you to use those classes or packages without having to fully qualify their names.

Initial capacity

: Initial capacity refers to the starting size or capacity allocated for an ArrayList when it is created using its constructor. It determines how many elements can be stored in the list before it needs to dynamically resize itself.

Insert element in ArrayList

: Inserting an element in an ArrayList refers to adding a new element at a specific position within the ArrayList. This operation shifts existing elements to accommodate the new element and maintains the order of the remaining elements.

Insertion Sort

: Insertion sort is a simple sorting algorithm where each iteration removes one element from an input data set and inserts it into its correct position within a partially sorted list until all elements are inserted.

Intrusion Detection Systems

: Intrusion Detection Systems (IDS) are security tools designed to detect unauthorized access attempts or suspicious activities within computer networks or systems.

Java Collections Framework

: The Java Collections Framework is a set of classes and interfaces in Java that provide implementations of common data structures like lists, sets, and maps. It offers a unified interface for working with collections of objects.

Linear Search

: Linear search is a simple searching algorithm that sequentially checks each element in a list until it finds the target value or reaches the end of the list.

Selection Sort

: Selection Sort is a simple sorting algorithm that repeatedly finds the minimum element from an unsorted portion of the list and swaps it with the first element of that portion until the entire list is sorted.

size()

: The size() method is used to determine the total number of elements present in a collection, such as a list or array.

Traversing ArrayLists

: Traversing ArrayLists refers to the process of accessing and examining each element in an ArrayList. It involves iterating through the elements sequentially, usually using a loop.

Wrapper Classes

: Wrapper classes are classes in Java that provide a way to wrap primitive data types into objects. They allow us to perform operations on primitives as if they were objects.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.