The Wayback Machine - https://web.archive.org/web/20211129033051/https://www.geeksforgeeks.org/scala-int-toend-int-method-with-example/
Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Scala Int to(end: Int) method with example

  • Last Updated : 30 Jan, 2020

The to(end: Int) method is utilized to return a range from the stated int 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: Int): Inclusive

Return Type: It returns the range.

Example #1:




// Scala program of Int to() 
// method 
    
// Creating object 
object GfG 
{  
    
    // Main method 
    def main(args:Array[String]) 
    { 
        // Applying to() method  
        val result = 5.to(10) 
            
        // Displays output 
        println(result) 
        
    } 
}  
Output:
Range(5, 6, 7, 8, 9, 10)

Example #2:




// Scala program of Int to() 
// method 
    
// Creating object 
object GfG 
{  
    
    // Main method 
    def main(args:Array[String]) 
    { 
        // Applying to() method  
        val result = 20.to(25) 
            
        // Displays output 
        println(result) 
        
    } 
}  
Output:
Range(20, 21, 22, 23, 24, 25)



My Personal Notes arrow_drop_up
Recommended Articles
Page :