w3resource

Scala Programming: Convert all the characters in a string to lowercase, uppercase


Write a Scala program to convert all the characters to lowercase, uppercase strings.

Sample Solution:

Scala Code:

object Scala_String {

  def main(args: Array[String]): Unit = {
    val str = "The Quick BroWn FoX!";

    // Convert the above string to all lowercase.
    val lowerStr = str.toLowerCase();
    val upperStr = str.toUpperCase();

    // Display the two strings for comparison.
    println("Original String: " + str);
    println("String in lowercase: " + lowerStr);
    println("String in uppercase: " + upperStr);
  }
}

Sample Output:

Original String: The Quick BroWn FoX!
String in lowercase: the quick brown fox!
String in uppercase: THE QUICK BROWN FOX! 

Go to:


PREV :Write a Scala program to get a substring of a given string between two specified positions.
NEXT : Write a Scala program to trim any leading or trailing whitespace from a given string.

Scala Code Editor :

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.