Java 中的substring()方法
目录
substring()
方法返回字符串的子字符串。
语法
public String substring(int beginIndex) 或 public String substring(int beginIndex, int endIndex)
参数
- beginIndex — 起始索引(包括), 索引从 0 开始。
- endIndex — 结束索引(不包括)。
返回值
子字符串。
public class Test { public static void main(String args[]) { String Str = new String("www.mybj123.com"); System.out.print("返回值 :" ); System.out.println(Str.substring(4) ); System.out.print("返回值 :" ); System.out.println(Str.substring(4, 10) ); } }
以上程序执行结果为:
返回值 :mybj123.com 返回值 :mybj123
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » Java 中的substring()方法
码云笔记 » Java 中的substring()方法