Java List get() MethodThe get() method of List interface returns the element at the specified position in this list. SyntaxParametersThe parameter 'index' represents the index of the elements to return. ReturnThe get() method returns the element at the specified position in this list. Throws:IndexOutOfBoundsException- If the index is out of range i.e. index<0 or index>=size(). Example 1Test it NowOutput: Element 0 stored at Index : 0 Element 1 stored at Index : 1 Element 2 stored at Index : 2 Element 3 stored at Index : 3 Element 4 stored at Index : 4 Element 5 stored at Index : 5 Example 2Test it NowOutput: ID : 17 Name :Ajeet Kumar Age : 36 Example 3Test it NowOutput: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: -1, Size: 3 atjava.util.LinkedList.checkElementIndex(LinkedList.java:555) atjava.util.LinkedList.get(LinkedList.java:476) at com.javaTpoint.JavaListGetExample3.main(JavaListGetExample3.java:12) Next TopicJava List |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India