As many have already told you:
mainList.get(3);
Be sure to check the ArrayList Javadoc.
Also, be careful with the arrays indices: in Java, the first element is at index 0
. So if you are trying to get the third element, your solution would be mainList.get(2);
More Related Contents:
- NumberFormatException not wrking java
- Write a program that takes an array/arraylist of integer and finds longest sub array/arraylist whose entries are equal [closed]
- Getting Arraylist IndexOutOfBoundsException
- How to create a Java ArrayList in C
- Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 6, Size: 6 [duplicate]
- Create ArrayList from array
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- Convert list to array in Java [duplicate]
- Java List.add() UnsupportedOperationException
- How do I find out what type each object is in a ArrayList?
- Moving items around in an ArrayList
- From Arraylist to Array
- Trouble with Gson serializing an ArrayList of POJO’s
- Add multiple items to an already initialized arraylist in Java
- Finding duplicate values in arraylist
- Empty an ArrayList or just create a new one and let the old one be garbage collected? [duplicate]
- Simple way to compare 2 ArrayLists
- How to use invokeAll() to let all thread pool do their task?
- Hash Set and Array List performances
- Scanner skipping every second line from file [duplicate]
- Check if an ArrayList contains every element from another ArrayList
- Adding to an ArrayList Java
- Can not deserialize instance of java.util.ArrayList out of VALUE_STRING
- Merging two arrayLists into a new arrayList, with no duplicates and in order, in Java
- Time Complexity for Java ArrayList
- ArrayList vs LinkedList from memory allocation perspective
- new ArrayList() failing in Java
- Java ArrayList how to add elements at the beginning
- Vector vs Collections.synchronizedList(ArrayList)
- Remove object from ArrayList with some Object property