子串索引范围 [英] substring index range

查看:80
本文介绍了子串索引范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

public class Test {
    public static void main(String[] args) {
        String str = "University";
        System.out.println(str.substring(4, 7));
    }   
}

输出 ers

我真的不明白子串方法是如何工作的。索引是否从0开始?如果我从0开始, e 在索引4但是char i 是7,所以输出将是 ersi

I do not really understand how the substring method works. Does the index start at 0? If I start with 0, e is at index 4 but char i is at 7 so the output would be ersi.

推荐答案

0:U

1:n

2:i

3:v

4:e

5:r

6:s

7:我

8:t

9:y

开始索引包含

结束指数是独占的

Javadoc链接

这篇关于子串索引范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆