java - Else statement executing -
this question has answer here:
- java: substring index range 10 answers
i new java programming , doing practice code via website, clarity on below
given:
string str = "jason"; str.substring(4,5); result = "n"
question: method substring
parameters (begin_index, end_index)
. there no index of 5 variable str
. java automatically -1 when comes length method of string?
the substring()
method "inclusive exclusive".
this means in jason, when provided (4, 5) parameters, it's inclusive of index 4 (n), exclusive of index 5. index 5 doesn't exist, it's exclusive it's okay.
note .length not 0 indexed. if try .length you'll 5. string character positions 0 indexed. jason indexed have 0 on j , 4 on n, though length 5.
Comments
Post a Comment