Java ArrayList Exercises, Practice & Solutions
Java Collection: ArrayList Exercises [22 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
ArrayList:
In Java, an ArrayList is a resizable array implementation of the List interface provided by the Java Collections Framework. It's part of the java.util package. Unlike arrays, which have a fixed size, ArrayList can dynamically grow and shrink in size as elements are added or removed. This makes it a more flexible data structure for handling collections of objects.
1. Write a Java program to create an array list, add some colors (strings) and print out the collection.
Click me to see the solution
2. Write a Java program to iterate through all elements in an array list.
Click me to see the solution
3. Write a Java program to insert an element into the array list at the first position.
Click me to see the solution
4. Write a Java program to retrieve an element (at a specified index) from a given array list.
Click me to see the solution
5. Write a Java program to update an array element by the given element.
Click me to see the solution
6. Write a Java program to remove the third element from an array list.
Click me to see the solution
7. Write a Java program to search for an element in an array list.
Click me to see the solution
8. Write a Java program to sort a given array list.
Click me to see the solution
9. Write a Java program to copy one array list into another.
Click me to see the solution
10. Write a Java program to shuffle elements in an array list.
Click me to see the solution
11. Write a Java program to reverse elements in an array list.
Click me to see the solution
12. Write a Java program to extract a portion of an array list.
Click me to see the solution
13. Write a Java program to compare two array lists.
Click me to see the solution
14. Write a Java program that swaps two elements in an array list.
Click me to see the solution
15. Write a Java program to join two array lists.
Click me to see the solution
16. Write a Java program to clone an array list to another array list.
Click me to see the solution
17. Write a Java program to empty an array list.
Click me to see the solution
18. Write a Java program to test whether an array list is empty or not.
Click me to see the solution
19. Write a Java program for trimming the capacity of an array list.
Click me to see the solution
20. Write a Java program to increase an array list size.
Click me to see the solution
21. Write a Java program to replace the second element of an ArrayList with the specified element.
Click me to see the solution
22. Write a Java program to print all the elements of an ArrayList using the elements' position.
Click me to see the solution
Java Practice online
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/java-exercises/collection/array-list.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics