Read String line by line

前端 未结 11 1713
迷失自我
迷失自我 2020-11-29 16:38

Given a string that isn\'t too long, what is the best way to read it line by line?

I know you can do:

BufferedReader reader = new BufferedReader(new          


        
11条回答
  •  广开言路
    2020-11-29 17:20

    Using Apache Commons IOUtils you can do this nicely via

    List lines = IOUtils.readLines(new StringReader(string));
    

    It's not doing anything clever, but it's nice and compact. It'll handle streams as well, and you can get a LineIterator too if you prefer.

提交回复
热议问题