Replacing the string content in a List of an object in Java -


i'm having problems replacing string field's content in list member.

i have list of objects , 1 of fields inside list string. example have following getters , setters.

public class myobject {   private string message;   private int numbers; ... 

let's assume i've created list of myobject , there 3 of them in list , i've added values them somewhere external database.

list<myobject> myobject = new arraylist<>(); 

the problem lies in string message. let's string field in first 3 entries equals following.

"first message" "second message" "third message" 

how can iterate through list of myobject's string message field , replace alphabetical content "first" new content such "1st" , on , forth.

you if class myobject allows update internal string; example providing setter method.

in other words:

  1. you iterate list of myobject objects
  2. for each of objects, have query message
  3. then have call setter update content

Comments