The get() method of java.util.AbstractList class is used to return the element at the specified position in this list.
public abstract E get(int index)
Parameters: This method takes index of the element as a parameter, the element at which is to be returned.
Returns Value: This method returns the element at the specified position in this list.
Exception: This method throws IndexOutOfBoundsException if the index is out of range (index = size()).
Below are the examples to illustrate the get() method.
ArrayListlist : [10, 20, 30, 40, 50] Element at index 3 : 40
ArrayListlist : [10, 20, 30, 40, 50] Trying to get the element from out of range index Exception thrown : java.lang.IndexOutOfBoundsException: Index: 7, Size: 5
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.