get() Method : Java.util.ArrayList
Declaration :
1 |
public E get(int index) |
Explanation :
Purpose | Method returns the element at the specified position in this list |
Parameters | index ==> The index of the element to return |
Return Value | Returns the element at the specified position in this list |
Exception | IndexOutOfBoundsException ==> If the index is out of range |
Example
The following example shows the usage of java.util.Arraylist.get() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package com.c4learn.arraylist; import java.util.ArrayList; public class ArrayListExamples { public static void main(String args[]) { // Create ArrayList 1 ArrayList<String> arrlist1 = new ArrayList<String>(); // Fill Elements in ArrayList 1 arrlist1.add("A"); arrlist1.add("B"); arrlist1.add("C"); arrlist1.add("D"); arrlist1.add("E"); arrlist1.add("F"); // Print Array List System.out.println("List Element : " + arrlist1); //Print Element at Position System.out.println("0th Element : " + arrlist1.get(0)); System.out.println("1st Element : " + arrlist1.get(1)); System.out.println("2nd Element : " + arrlist1.get(2)); System.out.println("3rd Element : " + arrlist1.get(3)); } } |
Output :
1 2 3 4 5 |
List Element : [A, B, C, D, E, F] 0th Element : A 1st Element : B 2nd Element : C 3rd Element : D |