带有示例的 Scala String toCharArray() 方法
toCharArray()方法用于将指定的字符串转换为CharArray 。
Method Definition: char[] toCharArray()
Return Type: It returns CharArray.
示例:1#
// Scala program of toCharArray()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toCharArray method
val result = "GeeksforGeeks".toCharArray()
for(m1<-result)
{
// Displays output
println(m1)
}
}
}
输出:
G
e
e
k
s
f
o
r
G
e
e
k
s
示例:2#
// Scala program of toCharArray()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toCharArray method
val result = "Nidhi".toCharArray()
for(m1 <- result)
{
// Displays output
println(m1)
}
}
}
输出:
N
i
d
h
i