Imagine I have several Stings containing large ammount of data. I must pass the concatenation of them to a method in a library I use. I can use either a String or a Reader for that.
ps: I already set the initial capacity of the StringBuilder for my first option, but this is no enough, so I am looking for a way to implement 2.
You could implement a custom Reader whose data is drawn from a list of your Strings. Your concrete subclass would be required to implement only two methods: read(char[], int, int)
and close()
. When your reader finishes consuming one String, move on to the next.