Jan
26
How to make the first character uppercase of each word of a List in Scala
Hey there! Welcome to ClearUrDoubt.com. In this post, we will look at a Scala program to make the first character uppercase of each word of an List. Let’s look at the program:
1 2 3 4 5 6 7 8 |
object CamelCaseWordMaker extends App { def capitalize(input: List[String]): List[String] = input .map(str => str.split(" ")) .map(arr => arr.map(_.capitalize).mkString(" ")) println(capitalize(List("hello", "world", "hello world"))) } |
Output: Happy learning. Please leave a reply in Read more