字符串转换为大写:
str.toUpperCase()
字符串转换为小写:
str.toLowerCase()
使用map进行全部转换
def main(args: Array[String]): Unit = {
/*
将 val names = List("ALice","Bob","Nick")中所有单词,全部转成大写
*/
var names = List("ALice","Bob","Nick")
names=names.map(_.toUpperCase()) //全部转换为大写
println(names)
names=names.map(_.toLowerCase()) //全部转换为小写
println(names)
}
原文:https://www.cnblogs.com/Jaryer/p/13600109.html