Javatpoint Logo
Javatpoint Logo

Scala String Methods



Scala String equals() Method Example

You can also use equal() method to compare two string objects. It returns true if both string object are equal otherwise returns false.

Output:

false
true

Scala compareTo() Method Example

The compareTo() method compares the given string with current string lexicographically. It returns positive number, negative number or 0.

If first string is greater than second string, it returns positive number (difference of character value). If first string is less than second string, it returns negative number and if first string is equal to second string, it returns 0.

Output:

11
0

Scala Concatenation Example by using + (Plus) Operator

In scala, you can concatenate string by using + operator. An example is given below in which two strings are concatenated by using + operator.

Output:

This is Scala string example

Scala String concat() Method Example

Apart from + operator, you can also use concat() method to concatenate two strings. It is a predefined method of string class.

Output:

This is Scala string example

Scala substring() Method Example

The substring() method is used to get substring from a string. By specifying start and end index as argument you can get substring according to your requirement. It is a predefined method of string class.

Output:

Scala




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA