Strings
Strings
SYNTAX : String_variable.length()
CODE :
OUTPUT :
● This function returns the characters
present at the specified position(index) in
charAt(int n) a string.
● Its return type is ‘char’
SYNTAX : String_variable.charAt(index
position)
CODE :
OUTPUT :
● This function returns the position(index)
indexOf(char ch)
of the first occurrence of a specified
character in a [Link] the character is not
present in the string, the method will
return -1.
● Its return type is ‘int’
SYNTAX : String_variable.indexOf(char)
CODE :
OUTPUT :
● This function removes blank spaces from
trim()
the beginning or end of a string.
● Its return type is ‘String’.
SYNTAX:
String_variable.trim();
CODE:
OUTPUT:
● This function concatenates two strings
together to produce a new string.
concat(String str) ● Its return type is ‘String’.
SYNTAX:
String_Variable_1.concat(String_Variable_2);
CODE:
OUTPUT:
● This function replaces all occurrences of
Replace(char oldChar,
a particular character or a group of
characters with another character or
char new char) ●
group of characters in the string.
Its return type is ‘String’.
SYNTAX:
String_Variable.replace(char oldChar, char
newChar);
CODE:
OUTPUT:
Thank you