Skip to content
Related Articles

Related Articles

Scala Char to(end: Char, step: Char) method with example
  • Last Updated : 11 Nov, 2019

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

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

Return Type: It returns the range.

Example: 1#

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

NumericRange(A, C, E, G)

Example: 2#

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

NumericRange(0, 3, 6, 9)



My Personal Notes arrow_drop_up
Recommended Articles
Page :