📜  带有示例的 Scala String toCharArray() 方法

📅  最后修改于: 2022-05-13 01:54:58.822000             🧑  作者: Mango

带有示例的 Scala String toCharArray() 方法

toCharArray()方法用于将指定的字符串转换为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