java - Else statement executing -


this question has answer here:

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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -