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
🌐
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 - import java.util.ArrayList; public ... names.add("Apple"); names.add("Samsung"); //update element of arraylist names.set(1, "Asus"); for(String name: names) { System.out.println(name); } } } ... In the following example, we will create ...
Discussions

java - ArrayList - How to modify a member of an object? - Stack Overflow
I have a number of Customer objects stored in an ArrayList. My Customer class has 2 data members: Name and Email. Now I want to modify just the Email for Customer "Doe". Now if "Doe" is located at... More on stackoverflow.com
🌐 stackoverflow.com
java - How do you update an array list - Stack Overflow
Its just like you did in delete method of yours, ArrayList as a static method set(int position, Object obj) this will update the object on that position. ... There is no edit method in interface java.util.List. More on stackoverflow.com
🌐 stackoverflow.com
arrays - Update specific object items inside Arraylist java - Stack Overflow
Moreover, since the returned Collection ... Collection has effects on the Map too (elements removal, object updating, etc.), thus avoiding code and data-structure duplication. :) 2015-10-07T14:36:24.603Z+00:00 ... @javatutorial you are right.... More on stackoverflow.com
🌐 stackoverflow.com
How to replace existing value of ArrayList element in Java - Stack Overflow
177 How do I update the element at a certain position in an ArrayList? 1308 Removing objects from a collection in a loop without causing ConcurrentModificationException More on stackoverflow.com
🌐 stackoverflow.com
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java ArrayList Insert/Replace At Index - Java Code Geeks
January 2, 2022 - We can use the set() for any type of object such as wrapper classes, String or any user-defined custom objects. It is allowed to update the values of the array list based on the condition while iterating it with the help of set() method.
🌐
w3resource
w3resource.com › java-exercises › collection › java-collection-exercise-5.php
Java - Update specific array element by given element
May 21, 2025 - Write a Java program to update an array element by the given element. ... import java.util.*; public class Exercise5 { public static void main(String[] args) { // Creae a list and add some colors to the list List<String> list_Strings = new ArrayList<String>(); list_Strings.add("Red"); list_Strings.add("Green"); list_Strings.add("Orange"); list_Strings.add("White"); list_Strings.add("Black"); // Print the list System.out.println(list_Strings); // Update the third element with "Yellow" list_Strings.set(2, "Yellow"); // Print the list again System.out.println(list_Strings); } }
🌐
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.
🌐
YouTube
youtube.com › knowledge to share
how to update elements in ArrayList in java. - YouTube
program of update Existing element in arrayList with following steps 1. find intex of element which we want to update in arraylist 2.update element with set ...
Published   December 24, 2017
Views   3K
Find elsewhere
🌐
CodeSpeedy
codespeedy.com › home › how to modify element or elements of an arraylist in java
Modify ArrayList Elements Java Program - CodeSpeedy
September 26, 2023 - Java program to change any element in an ArrayList. We will use set() method to modify or replace aJny particular element of an ArrayList
🌐
GeeksforGeeks
geeksforgeeks.org › java › update-the-list-items-in-java
Java Program to Update the List Items - GeeksforGeeks
July 23, 2025 - public Object set(int index, Object element) Return Value: The element that is at the specified index · Exception Throws: IndexOutOfBoundsException This occurs when the index is out of range. index < 0 or index >= size() Below is the implementation to Update the List Items in Java: Java · // Java program to update the list items // Importing required classes import java.util.ArrayList; import java.util.List; // Main Class public class UpdateList { // Main driver method public static void main(String[] args) { // Creating a list of courses List<String> courses = new ArrayList<>(); // Adding c
🌐
Coderanch
coderanch.com › t › 375852 › java › update-Object-Child-Arraylist
How to update an Object within a Child Arraylist! (Java in General forum at Coderanch)
Great Dave! Thanks alot! Now i'm wondering if it's possible to only update 1 field in that Object? Instead of updating the whole Object back to the ArrayList, can i update just 1 field in that Object possibly? ie ((ArrayList) ara.get(i)).set(j,tarj=>nshr) ? where i would only update the nshr field?
🌐
Stack Overflow
stackoverflow.com › questions › 67184487 › how-do-you-update-an-array-list
java - How do you update an array list - Stack Overflow
Its just like you did in delete method of yours, ArrayList as a static method set(int position, Object obj) this will update the object on that position. ... There is no edit method in interface java.util.List.
🌐
Coderanch
coderanch.com › t › 439819 › java › Updating-modifying-elements-ArrayList
Updating/modifying elements in ArrayList (Beginning Java forum at Coderanch)
June 4, 2009 - The HashMap takes a unique key (your player name), and a value (your player Object). This way you can just code like this (pseudo): Get Player from HashMap with name="My name" if Player is null then create new Player and add to HashMap else if Player is not null then update Player stats That's a condensed version but changing your code from an ArrayList to a HashMap is not hard at all and will save you lots of time/energy.
🌐
Stack Overflow
stackoverflow.com › questions › 42658202 › how-can-i-update-my-array-list-data-values
java - How can i update my array list data values? - Stack Overflow
import java.util.ArrayList; import java.util.Random; public class Theatre { private ArrayList<Room> theatres; public Theatre(){ theatres = new ArrayList<Room>(); theatres.add(new Room("Theatre 1", 120)); theatres.add(new Room("Theatre 2", 180)); theatres.add(new Room("Theatre 3", 100)); theatres.add(new Room("Theatre 4", 120)); theatres.add(new Room("Theatre 5", 200)); theatres.add(new Room("Theatre 6", 180)); theatres.add(new Room("Theatre 7", 80)); theatres.add(new Room("Theatre 8", 50)); theatres.add(new Room("Theatre 9", 120)); theatres.add(new Room("Theatre 10", 150)); } public void addTh
🌐
Reddit
reddit.com › r/javahelp › how do you update elements of an array list that are processed from other methods?
r/javahelp on Reddit: How do you update elements of an Array List that are processed from other methods?
March 19, 2022 -

This is a continuation of this post.

I created a constructor employeePayReport. In that constructor I made an Array List whose each elements contain different methods of the Employee Class. My Employee Class is parent class and I have 3 child classes for it. I created an object, employeePayReport, in my main method, then I call different methods that would update the elements of ArrayList. I am getting an error while updating them and I am also struggling with how to store them.

Here is the code.

Top answer
1 of 2
4
Question 1 (from your code): You have a member variable called console. This is available everywhere in your employeePayReport class. You don't have to pass it. The function already knows about it. Just go ahead and use it. This is because console is inside the class's scope. For the other questions, did you want to go with the idea I had in the previous post of putting more functionality in the Employee class and letting them handle their own details? If not, then I'll try to help you with the approach that you are choosing. Please let me know.
2 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Reddit
reddit.com › r/javahelp › how to change the object in an arraylist ?
r/javahelp on Reddit: How to change the object in an arraylist ?
December 6, 2022 -

Hi, I'm not at all familiar with ArrayLists in java but I need to use them for this code and really need help. There's my code, I only translated the comments so that's what it does :

  • fill the terrain with ressources (sprout) : adds m (set at 10) sprouts into an arraylist. They are defined through the class Ressource that takes a name (set at the sprout emoji) and an amount set at 0 for the sprout because there's nothing to collect yet. Then they get randomly placed it an 10*10 tab (the println just say whether or not the object was successfully placed) then t.affiche displays the tab

  • make ressources grow (roses) : now that's the one I need help with, from what I researched list.set seemed to be the way to go about changing the elements but their ids are changing and therefore they don't appear in tab. I'm going to put some kind of randomizer on it but if it keeps the id it should just appear in the tab without me having to manually set it's position right ? Could anyone tell me how I could do that ?

ArrayList<Ressource> list= new ArrayList<Ressource> ();
		int m = 10; //nb of Ressource

//********************* fill the terrain with ressources (sprout)*******************

		 for (int i=0; i<m; i++){
		 	list.add(new Ressource(" 🌱 ",0));
		 	if (t.setCase((int)(Math.random()*(9)),(int)(Math.random()*(9)),list.get(i)))
			System.out.println("Ajout de " + list.get(i) +" valide !");
			else
			System.out.println("Ajout incorrect: problème de coordonnées !");
			
		}
		System.out.println(list);
		t.affiche(5);
		
		System.out.println("Informations sur le terrain:\n"+t);


//********************* make ressources grow (roses)*******************************

		for (int i=0; i<m; i++){
			list.set(i, new Ressource(" 🌹 ",(int)(Math.random()*(3)));
		}
		t.affiche(5);
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-set-method-example
Java ArrayList set() Method example
June 12, 2024 - In the end, we printed the updated list with new element. In this example, we have an ArrayList of Integer type. Let’s replace the elements using set() method. import java.util.ArrayList; public class SetExample { public static void main(String args[]) { ArrayList<Integer> arraylist = new ArrayList<>(); arraylist.add(1); arraylist.add(2); arraylist.add(3); arraylist.add(4); arraylist.add(5); arraylist.add(6); arraylist.add(7); 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); //Updating 4th element arraylist.set(3, 44); //Updating 5th element arraylist.set(4, 55); System.out.println("ArrayList after Update: "+arraylist); } }
🌐
Coderanch
coderanch.com › t › 410231 › java › ArrayList-update-remove
ArrayList update and remove (Beginning Java forum at Coderanch)
Instead of removing and re-adding, you can use the set(int index, Object value) instead, to really replace the value.