How to Replace the value of existing element in ArrayList

http://comfycozycouture.com/CCC/kipiwer/2014 jede bekanntschaft jede sympathische begegnung ist ein gewinn http://feelgoodbiochem.com/?milforw=rencontres-astronomiques-du-printemps&d73=ac http://wolontariatsportowy.com/fioepr/bioepr/6384 enter site sims dating online games free rencontre celibataire 85 best dating sites to join partnersuche geretsried follow link 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.

Syntax: public E set(int index, Element E)

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.

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);

  }

}

Output:

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