How to Replace the value of existing element in ArrayList

click this rencontre vietnamienne gratuit How to Replace the value of existing element in ArrayList If there is a need to update the list element based on the index then set method of ArrayList class can be used. The method set(int index, Element E) updates the element of specified index with the given element E.

more helpful hints Syntax: public E set(int index, Element E)

go to these guys informative post Example: In this example I have an ArrayList of Integer Type where I have added few elements and then I’m updating few of elements using set method of java.util.ArrayList class.

bar rencontre ville québec package ArraylistClass; import java.util.ArrayList; public class SetExample { public static void main(String[] args) { ArrayList<Integer> arraylist = new ArrayList<Integer>(); arraylist.add(1); arraylist.add(2); arraylist.add(3); arraylist.add(4); arraylist.add(5); System.out.println("ArrayList before update: "+arraylist); //Updating 1st element arraylist.set(0, 11); //Updating 2nd element arraylist.set(1, 22); //Updating 3rd element arraylist.set(2, 33); System.out.println("ArrayList after Update: "+arraylist); } }

check my site Output:

ArrayList before update: [1, 2, 3, 4, 5]
ArrayList after Update: [11, 22, 33, 4, 5]