ArrayList in the Java Collection Framework.

ArrayList Methods in java:

In Java, ArrayList is a part of the Java Collections Framework and provides many useful methods to store, manipulate, and retrieve data dynamically.

Commonly used ArrayList Methods:

1. Adding …


This content originally appeared on DEV Community and was authored by Pavithraarunachalam

ArrayList Methods in java:

In Java, ArrayList is a part of the Java Collections Framework and provides many useful methods to store, manipulate, and retrieve data dynamically.

Commonly used ArrayList Methods:

1. Adding Elements:

  • add(E e)-> Adds the elements at the end

Example:

List.add("Apple");
  • add(int index, E e) → Adds an element at the specified index.

Example:

list.add(1, "Banana");

  • addAll(Collection c) → Adds all elements from another collection.

Example:

list.addAll(otherList);

2.Accessing Elements:

  • get(int index) → Returns the element at the given index.

Examples:

String fruit = list.get(0);

3. Changing Elements:

  • set(int index, E e) → Updates the element at the specified index.

Example:

list.set(1, "Mango");

4. Removing Elements:

  • remove(int index) → Removes the element at the given index.

Example:

list.remove(2);

  • remove(Object o) → Removes the first occurrence of the given element.

Example:

list.remove("Apple");

  • clear() → Removes all elements from the list.

Example:

list.clear();

  1. Searching Elements:
  • contains(Object o) → Returns true if the list contains the element.

Example:

list.contains("Mango");

  • indexOf(Object o) → Returns the first index of the element, or -1 if not found.

Example:

int index = list.indexOf("Banana");

  • lastIndexOf(Object o) → Returns the last index of the element.

Example:

int index = list.lastIndexOf("Apple");

  1. Size and Empty Check:
  • size() → Returns the number of elements in the list.

EXample:

int count = list.size();

  • isEmpty() → Returns true if the list is empty.

Example:

isEmpty() → Returns true if the list is empty.

7. Converting to Array:

  • toArray() → Converts the list to an array.

Example:

Object[] arr = list.toArray();

8. Iteration:

  • iterator() → Returns an iterator to traverse the list.

  • listIterator() → Returns a list iterator for forward and backward traversal.

Example:

Iterator<String> it = list.iterator();

9. Sorting (Using Collections):

Example:

Collections.sort(list);


This content originally appeared on DEV Community and was authored by Pavithraarunachalam


Print Share Comment Cite Upload Translate Updates
APA

Pavithraarunachalam | Sciencx (2025-08-28T16:38:17+00:00) ArrayList in the Java Collection Framework.. Retrieved from https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/

MLA
" » ArrayList in the Java Collection Framework.." Pavithraarunachalam | Sciencx - Thursday August 28, 2025, https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/
HARVARD
Pavithraarunachalam | Sciencx Thursday August 28, 2025 » ArrayList in the Java Collection Framework.., viewed ,<https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/>
VANCOUVER
Pavithraarunachalam | Sciencx - » ArrayList in the Java Collection Framework.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/
CHICAGO
" » ArrayList in the Java Collection Framework.." Pavithraarunachalam | Sciencx - Accessed . https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/
IEEE
" » ArrayList in the Java Collection Framework.." Pavithraarunachalam | Sciencx [Online]. Available: https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/. [Accessed: ]
rf:citation
» ArrayList in the Java Collection Framework. | Pavithraarunachalam | Sciencx | https://www.scien.cx/2025/08/28/arraylist-in-the-java-collection-framework/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.