Scala学习笔记三

第一章 字符串

新建一个字符串变量:val s = "Hello,World!"

可以获取字符串的长度:s.length //12

可以连接字符串:val s = "Hello" + "World"

把String当做字符串序列来处理,可以通过foreach方法来遍历字符串中的每一个字符:"hello".foreach(println)

可以通过for循环把字符串当做字符序列来处理:for (c <- "hello") println(c)

在有序集合中有许多方法可用,使用filter函数式的方法:var result = "hello world".filter(_ != '1')

https://www.cnblogs.com/leesf456/p/6286183.html

原文地址:https://www.cnblogs.com/meixudong/p/11160200.html