1

Java 11 用String.lines()获取一行行流

 2 years ago
source link: https://www.jdon.com/62496
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Java 11 用String.lines()获取一行行流

如何将 String 转换为 Stream?lines() 方法返回字符串流。
如果输入字符串有石灰终止符,此方法将字符串分解为行。

支持的行终止符是'\n'、'\r' 和 '\r\n'。

“\n”:  换行符
“\r”: 回车符
“\r\n”:回车后紧跟换行符
String withLineTerminators = "Very gald \nto meet you \nMr. Jhon Cena";
Stream lineTeminatorStream =  withLineTerminators.lines();
lineTeminatorStream.forEach(line -> System.out.println(line));

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK