Javatpoint Logo
Javatpoint Logo

Scala String

In scala, string is a combination of characters or we can say it is a sequence of characters. It is index based data structure and use linear approach to store data into memory. String is immutable in scala like java. You can manipulate string and can apply method to get desire result but you can't change original string object.

Scala String Example

This is a simple string example in which we have created a string variable.


Scala string example

Scala Immutable String Example 1

In this example, we are creating a string variable and trying to modify string object. Let's see what happen.


Scala string example

Scala Immutable String Example 2

In this example, we are modifying the string and assigning it to a variable so that we can keep reference of modified string. Here, a new string object is created after modification. The s1 variable now refers to new string object. The old string object is still available in the memory but does not have any reference.


This is Scala string example 

Scala String Comparison Example

In scala, you can compare two string objects by using == (equal) method. The following program describes how to use equal operator. It returns boolean value either true or false.



Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA