How to create and add elements in the ArrayList ?
In given Java program expalin creation a simple ArrayList ,adding data to ArrayList and extract data from ArrayList.
package com.mindclues; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ArrayListExample { public static void main(String[] args) { //List Creation List list = new ArrayList(); //Add elements to ArrayList list.add("1"); list.add("2"); list.add("3"); list.add("4"); list.add("5"); Iterator iterator = list.iterator(); String str = null; while (iterator.hasNext()) { str = (String) iterator.next(); System.out.println("List Elements :" + str); } } }
List Elements :1 List Elements :2 List Elements :3 List Elements :4 List Elements :5
post a comment