Scala String toCharArray() method with example
Last Updated :
29 Oct, 2019
Improve
The toCharArray() method is utilized to convert a stated string to CharArray.
Scala
Scala
Method Definition: char[] toCharArray() Return Type: It returns CharArray.Example: 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)
}
}
}
// 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)
}
}
}
Output:
Example: 2#
G e e k s f o r G e e k s
// 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)
}
}
}
// 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)
}
}
}
Output:
N i d h i