- ✕Tá an achoimre seo ginte ag intleacht shaorga atá bunaithe ar roinnt foinsí ar líne. Úsáid na naisc "Foghlaim tuilleadh" chun amharc ar an mbunfhaisnéis fhoinseach.
The ArrayList class in Java is a resizable array that is part of the java.util package. Unlike a built-in array, the size of an ArrayList can be modified dynamically, allowing elements to be added or removed as needed. This makes ArrayList a flexible and powerful tool for managing collections of data.
Creating an ArrayList
To create an ArrayList, you need to import the ArrayList class from the java.util package and then instantiate it. Here is an example of creating an ArrayList to store strings:
import java.util.ArrayList;public class Main {public static void main(String[] args) {ArrayList<String> cars = new ArrayList<String>();}}Cóipeáilte!✕CóipeáilAdding Elements
You can add elements to an ArrayList using the add() method. You can also specify the position where the element should be added by providing an index:
cars.add("Volvo");cars.add("BMW");cars.add("Ford");cars.add(0, "Mazda"); // Insert element at the beginningCóipeáilte!✕CóipeáilAccessing Elements
Java ArrayList - W3Schools
An ArrayList keeps elements in the same order you add them, so the first item you add will be at index 0, the next at index 1, and so on.
Sampla de chód
// Create an ArrayList object called cars that will store stringsimport java.util.ArrayList; // import the ArrayList classArrayList<String> cars = new ArrayList<String>(); // Create an ArrayList objectArrayList in Java - GeeksforGeeks
17 Márta 2026 · ArrayList in Java is a resizable array provided in the java.util package. Unlike normal arrays, its size can grow or shrink dynamically as elements are added or removed.
Java ArrayList (With Examples) - Programiz
Learn how to use the ArrayList class in Java to create resizable arrays and perform various operations on them. See examples of adding, accessing, changing and …
Java ArrayList Class - Online Tutorials Library
Learn how to use the Java ArrayList class, a resizable array that implements the List interface. See the class declaration, constructors, methods, and examples of adding and removing elements.
Guide to the Java ArrayList - Baeldung
14 Noll 2024 · Learn how to use the ArrayList class from the Java Collections Framework, its properties, use cases, and advantages and disadvantages. See how to create, add, iterate, search, and remove …
Java ArrayList: The Ultimate Guide - W3docs
Learn how to create, manipulate, and use ArrayList in Java, a resizable array implementation of the List interface. See examples of adding, removing, modifying, and storing elements in ArrayList, and how to …
ArrayList in Java - Guru99
8 Samh 2024 · Learn what is ArrayList in Java, a dynamic array that can grow and shrink as needed. See the syntax and usage of common methods such as add, …
Java ArrayList: How to Declare, Create, Initialize ArrayList
5 Márta 2026 · Learn how to declare, create, initialize, and print an ArrayList in Java. This guide explains empty ArrayList creation, initialization with values, and …
Java ArrayList - DataCamp
Learn how to use Java ArrayList, a resizable array implementation of the List interface, to store dynamically sized collections of elements. See basic operations, sorting, iterating, and best practices …
- Iarrann daoine freisin