Introduction to Scala String
Scala string is an immutable object that means the 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.The string contains different predefined functions that are very useful to perform various operations on strings.
var I = “intellipaat”
Some methods are –
Kick-start your career in Scala with the perfect Scala Training Course now!
- 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.
Come to Intellipaat’s Apache Spark and Scala Community if you have more queries on Scala!
- startsWith – Tests whether this string starts with the argument of this method.
- endsWith – Tests whether this string ends with the argument of this method.
Get familiar with the top Apache Spark and Scala Interview Questions to get a head start in your career!
- 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 the string and if it takes two arguments then first specify the starting of string and second string specify the ending of the string
Interested in learning Scala? Check out the Scala Training in Sydney!
- concat – This method appends its argument to this string
I = I.concat("Hello");
Check out our blog on Arrays in Scala.
- contains – Examine whether a string contains a particular substring or not.
println("contains specified string")
contains specified string
- replace – It takes two arguments from which the first argument is replaced by the second argument form the specified string.
- toLowerCase – converts all of the characters in this string to lower case.
- toUpperCase – converts all of the characters in this string to upper case.
Wish to get certified in Scala! Learn Scala from top Scala experts and excel in your career with Intellipaat’s Scala certification!
- trim – Returns a copy of the string with leading and trailing whitespace omitted.
- isEmpty – Returns true if method length returns 0.
- codePointAt – Returns the Unicode code point at the specified index.
- toCharArray – Transforms a string into an array