Scala string is an immutable object that means object cannot be modified. Each element of a string is associated with an index number. The first character is associated with the number 0, the second with the number 1, etc. Class java.lang.String contains different predefined functions which are very useful to perform various operations on strings.
var I = “intellipaat”
Some methods are –
length – Returns the number of Unicode code units in a string
charAt – It has an index number as an argument and returns the Char at the specified index.
startsWith – Tests whether this string starts with the argument of this method.
endsWith – Tests whether this string ends with the argument of this method.
indexOf – Returns the index within this string object of the first occurrence of the string argument.
substring – Returns a new string that is a substring of this string. It may take one or two arguments. If it takes one argument then substring begins with the specified index to the end of string and if it takes two argument then first specify the starting of string and second string specify the ending of string
concat – This method appends its argument to this string
I = I.concat("Hello");
contains – Examine whether a string contains a particular substring or not.