2(vi)
Write the output of the following String methods:
(a) "ARTIFICIAL".indexOf('I')
(b) "DOG and PUPPY".trim().length()
Show SolutionHide Solution↓
(a)
3
indexOf() returns the index of the first occurrence of the specified character within the string or -1 if the character is not present. First occurrence of 'I' in "ARTIFICIAL" is at index 3 (a string begins at index 0).
(b)
13
trim() removes all leading and trailing space from the string and length() returns the length of the string i.e., the number of characters present in the string. Thus, the output is 13.