im trying make one replace in string from a array but this dont work
dna[i].replace('T', 'C');
and with this way work?
"ATCTA".replace('T', 'C');
why dont work with array, how i can use use a replace in array[]
Now i have other problem, i want use various replaces in original string, how i can mahe this????
This works as expected. Double check your code if you follow a similiar pattern.
You may have expected, that
dna[i].replace('T', 'C');changes the content of the celldna[i]directly. This is not the case, the String will not be changed,replacewill return a new String where the char has been replaced. It’s necessary to assign the result of thereplaceoperation to a variable.To answer your last comment:
Strings are immutable – you can’t change a single char inside a String object. All operations on Strings (substring, replace, ‘+’, …) always create new Strings.
A way to make more than one replace is like this: