Read String line by line

前端 未结 11 1712
迷失自我
迷失自我 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:03

    The easiest and most universal approach would be to just use the regex Linebreak matcher \R which matches Any Unicode linebreak sequence:

    Pattern NEWLINE = Pattern.compile("\\R")
    String lines[] = NEWLINE.split(input)
    

    @see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html

提交回复
热议问题