Java substring() 方法

灰太狼 2023-02-26 06:24 65阅读 0赞

substring() 方法返回字符串的子字符串。

  1. public String substring(int beginIndex)
  2. public String substring(int beginIndex, int endIndex)

参数

  • beginIndex -- 起始索引(包括), 索引从 0 开始。
  • endIndex -- 结束索引(不包括)。

返回值

子字符串。

  1. 实例
  2. public class Test {
  3. public static void main(String args[]) {
  4. String Str = new String("www.runoob.com");
  5. System.out.print("返回值 :" );
  6. System.out.println(Str.substring(4) );
  7. System.out.print("返回值 :" );
  8. System.out.println(Str.substring(4, 10) );
  9. }
  10. }
  11. 以上程序执行结果为:
  12. 返回值 :runoob.com
  13. 返回值 :runoob

发表评论

表情:
评论列表 (有 0 条评论,65人围观)

还没有评论,来说两句吧...

相关阅读