- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Retrieve an element from ArrayList in Java
An element can be retrieved from the ArrayList in Java by using the java.util.ArrayList.get() method. This method has a single parameter i.e. the index of the element that is returned.
A program that demonstrates this is given as follows
Example
import java.util.ArrayList; import java.util.List; public class Demo { public static void main(String args[]) throws Exception { List aList = new ArrayList(); aList.add("James"); aList.add("George"); aList.add("Bruce"); aList.add("Susan"); aList.add("Martha"); System.out.println("The element at index 3 in the ArrayList is: " + aList.get(3)); } }
The output of the above program is as follows
The element at index 3 in the ArrayList is: Susan
Now let us understand the above program. The ArrayList aList is created. Then ArrayList.add() is used to add the elements to the ArrayList.
Then the ArrayList.get() method is used to retrieve the element at index 3 and this is displayed. A code snippet which demonstrates this is as follows
List aList = new ArrayList(); aList.add("James"); aList.add("George"); aList.add("Bruce"); aList.add("Susan"); aList.add("Martha"); System.out.println("The element at index 3 in the ArrayList is: " + aList.get(3));
- Related Articles
- How to remove an element from ArrayList in Java?
- Remove an element from an ArrayList using the ListIterator in Java
- Java Program to Remove Repeated Element from An ArrayList
- How to remove an element from ArrayList or, LinkedList in Java?
- Search an element of ArrayList in Java
- How to remove element from ArrayList in Java?
- Check existence of an element in Java ArrayList
- Retrieve the last element from a LinkedList in Java
- How to replace an element of an ArrayList in Java?
- Get the location of an element in Java ArrayList
- Replace an element in an ArrayList using the ListIterator in Java
- How do you search for an element in an ArrayList in Java?
- Add an element to specified index of ArrayList in Java
- Remove duplicate items from an ArrayList in Java
- How to create an ArrayList from an Array in Java?

Advertisements