7:17 am - Monday September 24, 2018

ArrayList Example Program for set(int index, E element)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of
set(int index, E element). This function used to replace specified element with given index position in the list
*/
import java.io.*;
import java.util.*;
public class ArrayListSet
{
public static void main(String arg[])throws Exception
{
ArrayList al=new ArrayList();//to create object for ArrayList class
al.add("a");//to add an element in arrayList
al.add("b");//to add an element in arrayList
al.add("c");//to add an element in arrayList
al.add("x");//to add an element in arrayList
System.out.println("before replace:"+al);
al.set(3,"d");//to replace specified element with given index position in the list
System.out.println("after replace:"+al);
}
}

Output:
before replace:[a,b,c,x]
after replace:[a.b.c.d]

BACK

Filed in: Z-A All Java Codes

Comments are closed.