Java 中的行分隔符
字符串没有换行。我们可以通过连接一个换行字符串形成两行。使用 System lineSeparator 来获取平台相关的换行字符串。
以下是一个示例。
示例
public class Demo {
public static void main(String[] args) {
String str = "one" + System.lineSeparator() + "two";
System.out.println(str);
}
}输出
one two
我们来看另一个示例。在基于 Linux 的系统上,该程序将运行正确。
示例
public class Demo {
public static void main(String[] args) {
String str = System.lineSeparator();
System.out.println((int) str.charAt(0));
}
}输出
10
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
Javascript
PHP