class CheckString {
 
    public static void main(String[] arguments) {
        String str = "Nobody ever went broke by buying IBM";
        System.out.println("The string is: " + str);
        System.out.println("Length of this string: "
            + str.length());
        System.out.println("The character at position 5: "
            + str.charAt(5));
        System.out.println("The substring from 26 to 32: "
            + str.substring(26, 32));
        System.out.println("The index of the character v: "
            + str.indexOf('v'));
        System.out.println("The index of the beginning of the "
            + "substring \"IBM\": " + str.indexOf("IBM"));
        System.out.println("The string in upper case: "
            + str.toUpperCase());
    }
}
The string is: Nobody ever went broke by buying IBM
Length of this string: 36
The character at position 5: y
The substring from 26 to 32: buying
The index of the character v: 8
The index of the beginning of the substring "IBM": 33
The string in upper case: NOBODY EVER WENT BROKE BY BUYING IBM
Press any key to continue . . .
我的问题是我substring() indexof()  toUpperCase() 这些字符串位置是不是都是从0开始啊? 

解决方案 »

  1.   

    问的问题很简单,楼主要学会用API文档,自己可以看API文档啊,然后自己试试不就知道了
      

  2.   

    substringpublic String substring(int beginIndex,
             int endIndex)    返回一个新字符串,它是此字符串的一个子字符串。该子字符串从指定的 beginIndex 处开始,直到索引 endIndex - 1 处的字符。因此,该子字符串的长度为 endIndex-beginIndex。    示例:         "hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile"     参数:
            beginIndex - 起始索引(包括)。
            endIndex - 结束索引(不包括)。
        返回:
            指定的子字符串。
        抛出:
            IndexOutOfBoundsException - 如果 beginIndex 为负,或 endIndex 大于此 String 对象的长度,或 beginIndex 大于 endIndex。
      

  3.   

    indexOfpublic int indexOf(String str,
        int fromIndex)    返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。返回的整数是满足下式的最小 k 值:             k >= Math.min(fromIndex, this.length()) && this.startsWith(str, k)     如果不存在这样的 k 值,则返回 -1。    参数:
            str - 要搜索的子字符串。
            fromIndex - 开始搜索的索引位置。
        返回:
            指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
      

  4.   

    toUpperCasepublic String toUpperCase()    使用默认语言环境的规则将此 String 中的所有字符都转换为大写。此方法等效于 toUpperCase(Locale.getDefault())。    注: 此方法与语言环境有关,如果用于应独立于语言环境解释的字符串,则可能生成不可预料的结果。示例有编程语言标识符、协议键、HTML 标记。例如,"title".toUpperCase() 在 Turkish(土耳其语)语言环境中返回 "T?TLE",其中“?”是 LATIN CAPITAL LETTER I WITH DOT ABOVE 字符。对于与语言环境有关的字符,要获得正确的结果,请使用 toUpperCase(Locale.ENGLISH)。    返回:
            要转换为大写的 String。
        另请参见:
            toUpperCase(Locale)