how to change value in arraylist java code example
Example 1: update value of an arraylist java
yourExistingArray.set(1, "New Value");
Example 2: modify element in list java
list.set( 2, "New" );
Example 3: arraylist replace value java
list.set(1,"new value");
List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");
System.out.println(list);
list.set(1,"new");
System.out.println(list);
Example 4: java set value of arraylist
import java.util.ArrayList;
public class SetExample {
public static void main(String args[]) {
ArrayList<Integer> arraylist = new ArrayList<Integer>();
arraylist.add(1);
System.out.println(arrayList.get(0));
arrayList.set(0, 2)
System.out.println(arrayList.get(0));
}
}