Hello everyone,

I am having some trouble getting replaceAll(); to work. I am trying to apply it to a String array that has 4 rows and writing the portion of the code as follows

for(int i = 0; i < 4; i++){

        lines[i].replaceAll("this", "that");
       
    }

For one reason or another "this" is NOT being replaced even once by "that" ..

I have everything I know how. Can anyone help ?

greatly appreciated,

Colin

Remember that Strings are immutable.
What you're doing is creating a new String where "this" is replaced with "that" and then immediately you throw that String away, leaving the old one in the array.

What you are looking for is something like

array[i] = array[i].replaceAll("this", "that");
commented: Very Very Helpful !!!! +1

Thank You , thank You , thank You , Thank you !!

for (int i = 0; i < 100000; i++)
System.out.println("THANK YOU !!!!");


Remember that Strings are immutable.
What you're doing is creating a new String where "this" is replaced with "that" and then immediately you throw that String away, leaving the old one in the array.

What you are looking for is something like

array[i] = array[i].replaceAll("this", "that");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.