Let arrList be the ArrayList and newValue the new String, then just do:

arrList.set(5, newValue);

This can be found in the java api reference here.

Answer from HaskellElephant on Stack Overflow
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java ArrayList Insert/Replace At Index - Java Code Geeks
January 2, 2022 - Use the ArrayList.add(int index, Object value) method to add any object or element at the specific index of ArrayList and use ArrayList.set(int index, E value) to replace the value at the specific index of ArrayList in java.
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › add element(s) at specified index to arraylist in java
Add Element(s) at Specified Index to ArrayList in Java
August 7, 2023 - The ArrayList.add() method inserts the specified element at the specified position in this list. It shifts the element currently at that position (if any) and any subsequent elements to the right (will add one to their indices).
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › replace an existing item in arraylist
Replace an Existing Item in ArrayList
January 12, 2023 - Once we have the index, we can use set() method to update the replace the old element with a new item. Find the index of an existing item using indexOf() method. Use set(index, object) to update with the new item.
🌐
TutorialKart
tutorialkart.com › java › how-to-update-an-element-of-arraylist-in-java
How to Update an Element of ArrayList in Java?
December 21, 2020 - To update or set an element or object at a given index of Java ArrayList, use ArrayList.set() method. ArrayList.set(index, element) method updates the element of ArrayList at specified index with given element.
🌐
Baeldung
baeldung.com › home › java › java list › replace element at a specific index in a java arraylist
Replace Element at a Specific Index in a Java ArrayList | Baeldung
April 3, 2025 - The most common way to replace an element in Java ArrayList is to use the set (int index, Object element) method. The set() method takes two parameters: the index of the existing item and the new item. The index of an ArrayList is zero-based.
🌐
Java67
java67.com › 2016 › 08 › how-to-replace-element-of-arraylist-in-java.html
How to replace an element of ArrayList in Java? Example | Java67
Here is an example of replacing an existing value from ArrayList in Java. In this example, I have an ArrayList of String which contains names of some of the most popular and useful books for Java programmers. Our example replaces the 2nd element of the ArrayList by calling the ArrayList.set(1, "Introduction to Algorithms") because the index of the array starts from zero.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-set-method-in-java-with-examples
Java ArrayList set() Method - GeeksforGeeks
5 days ago - Explanation: In the above example, ... in an ArrayList and prints both the updated list and the replaced element. ... Returns Value: It returns the element that was previously at the specified position. Exception: IndexOutOfBoundsException: Thrown if the index is out of the valid range (index < 0 or index >= size). Example 2: Here, this example will show how trying to replace an element at an invalid index results in an exception. ... // Handling IndexOutOfBoundsException import java.util.ArrayList; ...
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-set-method-example
Java ArrayList set() Method example
June 12, 2024 - import java.util.ArrayList; public class ArrayListExample { public static void main(String[] args) { // Create an ArrayList and add some elements ArrayList<String> list = new ArrayList<>(); list.add("Apple"); list.add("Banana"); list.add("Orange"); list.add("Mango"); System.out.println("Original list: " + list); // Replacing the second element (element at index 1) String oldElement = list.set(1, "Blueberry"); System.out.println("Replaced element: " + oldElement); System.out.println("Updated list: " + list); } }
🌐
Javaprogramto
javaprogramto.com › 2021 › 12 › java-arraylist-insert-at-index.html
Java ArrayList Insert/Replace At Index - JavaProgramTo.com
Use the ArrayList.add(int index, Object value) method to add any object or element at the specific index of ArrayList and use ArrayList.set(int index, E value) to replace the value at the specific index of ArrayList in java.
🌐
Codemia
codemia.io › knowledge-hub › path › java_arraylist_replace_at_specific_index
Java ArrayList replace at specific index
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
CodeGym
codegym.cc › java blog › java collections › how to replace an element in java arraylist
How to Replace an Element in Java ArrayList
October 11, 2023 - Nevertheless in ArrayList replace is pretty convenient to implement using the set method. arrayList.set(int index, dataType arrayListElement); The method takes 2 parameters. int index — The first one is the index of the element in ArrayList. ...
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › set
Java ArrayList set() - Replace Element | Vultr Docs
November 13, 2024 - This code initializes an ArrayList of colors, replaces the second element "Green" with "Yellow", and prints the updated list. Be aware that using an invalid index will throw an IndexOutOfBoundsException. Always check if the index is within the bounds of the list size before attempting to set a value.
🌐
JavaGoal
javagoal.com › home › how to replace element in an arraylist?
replace element in an ArrayList and set() method - JavaGoal
July 27, 2020 - We have seen how to add and remove elements from ArrayList in java. But sometimes, there may be a situation when we want to replace the element in ArrayList. We can use set(int index, E element) to replace the element. The set(index, E element) method is used to set the specified element at ...
🌐
Sololearn
sololearn.com › en › Discuss › 521844 › how-can-i-change-an-element-of-array-that-is-defined-in-arraylist-in-java
How can I change an element of array that is defined in arraylist in java? | Sololearn: Learn to code for FREE!
July 8, 2017 - You want to move something from the arraylist to the array?¿ If that is what you want, it's the same as you'd normally modify an array value. myArray[index] = myList.get(index); // index for ^array. index for ^list. myArray[0] = myList.get(5); // index at 0 is now the value of the lists index at 5. If that wasn't what you wanted, can you give an example? ... Oh. You can actually do the exact same code you just did with the array in java.