String str = "我爱 Java 编程"; String result = str.substring(3); System.out.println(result); // 输出:Java 编程
图1 字符串中的字符索引
public static void main(String[] args) { String day = "Today is Monday"; //原始字符串 System.out.println("substring(0)结果:"+day.substring(0)); System.out.println("substring(2)结果:"+day.substring(2)); System.out.println("substring(10)结果:"+day.substring(10)); System.out.println("substring(2,10)结果:"+day.substring(2,10)); System.out.println("substring(0,5)结果:"+day.substring(0,5)); }输出结果如下所示:
substring(0)结果:Today is Monday substring(2)结果:day is Monday substring(10)结果:onday substring(2,10)结果:day is M substring(0,5)结果:Today
本文链接:http://task.lmcjl.com/news/10232.html