Wednesday, March 11, 2015

Replace an element at java pgm



Replace an element at specified index of Java ArrayList
import java.util.ArrayList;
public class ReplaceElementAtSpecifiedIndexArrayListExample
{
public static void main(String[] args)
{
ArrayList arrayList = new ArrayList();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.set(1,"REPLACED ELEMENT");
System.out.println("ArrayList contains...");
for(int index=0; index < arrayList.size(); index++)
System.out.println(arrayList.get(index));
   }
}

No comments:

Post a Comment