Open In App

Scala Char to(end: Char) method with example

Improve
Improve
Like Article
Like
Save
Share
Report

The to(end: Char) method is utilized to return a range from the stated character to the ‘end’, which is given in the arguments list but here “step” is not specified in the arguments list.

Method Definition: def to(end: Char): Inclusive[Char]

Return Type: It returns the range.

Example: 1#




// Scala program of to()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Applying to() method 
        val result = 'A'.to('G')
          
        // Displays output
        println(result)
      
    }


Output:

NumericRange(A, B, C, D, E, F, G)

Example: 2#




// Scala program of to()
// method
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Applying to() method
        val result = ('0').to('9')
          
        // Displays output
        println(result)
      
    }


Output:

NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)


Last Updated : 11 Nov, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads