I'm trying to replace/remove certain characters within a String ArrayList. Here is the code that I've already tried:
for (int i = 0; i < newList.size(); i++) {
if (newList.get(i).contains(".")) {
newList.get(i).replace(".", "");
}
}
I tried iterating through the ArrayList and, if any of the elements contained a ".", then to replace that with emptiness. For example, if one of the words in my ArrayList was "Works.", then the resulted output would be "Works". Unfortunately, this code segment does not seem to be functioning. I did something similar to remove any elements which contains numbers and it worked fine, however I'm not sure if there's specific syntax or methods that needs to be used when replacing just a single character in a String while still keeping the ArrayList element.
Stringis immutable - so it cannot be changed - soreplace()must return a new (modified)String, which is not being used in your code