We use method get(int index) for get any element at specific index.
import java.util.ArrayList;
public class GetElement {
public static void main(String[] args) {
ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add("c");
arr.add("php");
arr.add("html");
arr.add("java");
// print arraylist
System.out.println("arrayList is = " + arr);
System.out.println("Element At Index 2 ="+arr.get(2));
}
}
Output:
arrayList is = [c, php, html, java]
Element At Index 2 =html
Storing Java Object In ArrayList
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
import java.util.ArrayList;
public class GetElement {
public static void main(String[] args) {
ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add("c");
arr.add("php");
arr.add("html");
arr.add("java");
// print arraylist
System.out.println("arrayList is = " + arr);
System.out.println("Element At Index 2 ="+arr.get(2));
}
}
Output:
arrayList is = [c, php, html, java]
Element At Index 2 =html
Related Posts:
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
No comments:
Post a Comment