ArrayListGetExample.java
Output
import java.util.ArrayList; /* * Example of get(int index) method */ public class ArrayListGetExample { public static void main( String[] args ) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Ram"); arrayList.add("Dave"); arrayList.add("Peter"); arrayList.add("Julia"); arrayList.add("Akram"); System.out.println("ArrayList : " + arrayList + "\n"); String name = arrayList.get(2); System.out.println("Value in the 2nd index : " + name); } }
ArrayList : [Ram, Dave, Peter, Julia, Akram] Value in the 2nd index : Peter
https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoGet.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment