I know that for an object, we can collect and update the object for the collection at our discretion, but for immutable objects, such as strings, how can we update the array with a new object without converting it to an array again.
For example, I have an array of strings. I want to iterate over each row and crop it. Otherwise, I would have to do something like this:
Arrays.stream(str).map(c -> c.trim()).collect(Collectors.toList())
In the end, I will get List, not String [], which I originally gave. Its a lot of processing. Is there a way to do something similar to:
for(int i = 0; i < str.length; i++) {
str[i] = str[i].trim();
}
using java threads?
source
share