如何提取 String 中的子字符串?

在Java中,可以使用substring()方法提取String中的子字符串。该方法的参数为起始位置和终止位置(不包括终止位置的字符),可以根据需要进行调整。例如:

String str = "hello world";

String subStr = str.substring(0, 5); // subStr的值为"hello"

需要注意的是,参数索引从0开始,且终止位置大于等于起始位置。

(0)

相关推荐