Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting an ArrayList of Strings into A BufferedReader

How do I converting an ArrayList of strings into a BufferedReader? I'm open to making the ArrayList as an Input Stream instead, but I want an easy way to add strings into the data structure that will eventually be captured by the BufferedReader.

like image 573
syker Avatar asked Dec 04 '22 10:12

syker


1 Answers

This may not be the quickest or most efficient way, but this is the first thing I thought of:

// Assume the ArrayList is named stringList
StringBuilder buffer = new StringBuilder();
for(String current : stringList) {
    buffer.append(current).append("\n");
}

BufferedReader br = new BufferedReader(new StringReader(buffer.toString()));
like image 173
Powerlord Avatar answered Dec 06 '22 00:12

Powerlord