object Demo {
def main(args: Array[String])
{
var s1 = "Scala string example"
var s2 = "Hello Scala"
var s3 = "Hello Scala"
var upper=s1.toUpperCase()
var lower=s1.toLowerCase()
var length=s1.length()
println("--------------------------------String Equals------------------------------------")
println(s1.equals(s2))
println(s2.equals(s3))
println(" ")
println("--------------------------------String Compare------------------------------------")
// * s1 > s2 => positive number , s1 < s2s2 => negative number ,s1 == s2 => 0 */
println(s1.compareTo(s2))
println(s2.compareTo(s3))
println(" ")
println("--------------------------------String Concat------------------------------------")
println(s2 + "this is " + s1)
println(s1.concat(s2))
println(" ")
println("--------------------------------String substring------------------------------------")
println(s1.substring(0,5))
println(s1.substring(6,12))
println(" ")
println("--------------------------------String uppercase------------------------------------")
println("To upper case:" + upper)
println(" ")
println("--------------------------------String lowercase------------------------------------")
println("To lower case:" + lower)
println(" ")
println("--------------------------------String length------------------------------------")
println("length of the string is:" + length)
}
}
Output:
--------------------------------String Equals------------------------------------
false
true
--------------------------------String Compare------------------------------------
11
0
--------------------------------String Concat------------------------------------
Hello Scalathis is Scala string example
Scala string exampleHello Scala
--------------------------------String substring------------------------------------
Scala
string
--------------------------------String uppercase------------------------------------
To upper case:SCALA STRING EXAMPLE
--------------------------------String lowercase------------------------------------
To lower case:scala string example
--------------------------------String length------------------------------------
length of the string is:20