Scala - Capitalizing a list of strings using for expression Code Example

The code for Capitalizing a list of strings using for expression

val cities = List("gwalior", "new delhi", "mumbai")

// You can create a list of capitalized 
// strings with this for-expression
val ucCities = for (city <- cities) yield city.capitalize

// Printing
println(cities)
println(ucCities)

/*
Output:
List(gwalior, new delhi, mumbai)
List(Gwalior, New delhi, Mumbai)
*/
Code by IncludeHelp, on August 8, 2022 02:09

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.