简体   繁体   中英

what is the meaning of arguments in substring method of String class

class Test {

    public static void main(String[] args) {
       String str="Hello world";
        System.out.println(str.substring(0, 4));
    }
}

why the output is not Hello ? if the substring method's arguments indicate the starting and ending point respectively. And here strating from 0 index why does it end before index 4.i mean why been here the index 4 character not printed

str.substring(0, 4) retrieve part of the given str from index 0 inclusive to index 4 exclusive. Result is Hell .

See Java doc for String class: public CharSequence subSequence(int beginIndex, int endIndex)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM