change arraylist value code example

Example 1: update value of an arraylist java

//first arg it is position
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");

//example ..

List<String> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");
System.out.println(list); // [one,two,three]
list.set(1,"new");
System.out.println(list); //[one,new,three]

Tags:

Java Example