This is a memo of Java substrings that are often used in business.
Specify the extraction start position (beginIndex) in the first argument of the substring method and the extraction end position (endIndex) in the second argument.
Substrings start at beginIndex and represent endIndex-1.
"Sample characters".substring(beginindex, endindex-1);
beginindex starts counting from 0th. Same as counting subscripts in an array.
"Sample characters".substring(0, 4);
//Output result:sample
In this case, the character length is 4-0 = 4 Therefore, 4 characters are displayed as a substring.
Recommended Posts