String Methods
Learn some built-in functions allowed on strings.
We’ve already covered three methods in this unit: length()
, indexOf()
, and concat()
. In this section, we’ll go through some more methods.
Extracting a part of a string
Suppose we have a string “I love Java”, and we want to find a part of the string between specific indexes. For example, if we want to find the part of “I love Java” inclusively between the 2nd and 5th index, what will we do?
First, we’ll get to the 2nd index, then onwards we will start noting the characters. Once we reach the 5th index, we’ll note the character at that position and will stop moving any further. Let’s do it for “I love Java”.
Get hands-on with 1400+ tech skills courses.