I have a function which takes a String list as parameter which, at the end of the function, I want to update with new values but preserve its contents to the main program. To be more specific, I create another String list and at the end of the function I want to copy everything from the second list to the first and also I want the first list to “carry” the new data to the main program. Does Java give me the ability to do that? If not, is there any other way?
Share
The answer is Yes, Java provides a way for you to do that.
If you have a method that accepts a List of Strings as a parameter, it may do something like this:
This creates the new list of modified strings, appends those to the original list (which the caller will see) and also returns the new list of Strings separately. You could skip returning the list if you want.