Skip to content
Related Articles
Open in App
Not now

Related Articles

Scala String substring(int beginIndex, int endIndex) method with example

Improve Article
Save Article
Like Article
  • Last Updated : 29 Oct, 2019
Improve Article
Save Article
Like Article

The substring(int beginIndex, int endIndex) method is utilized to find the sub-string from the stated String which starts and ends with the index specified.

Method Definition: String substring(int beginIndex, int endIndex)

Return Type: It returns string which is the part of the stated String.

Note: It is same as sub-sequence method but the only difference between the two is that sub-sequence returns CharSequence but the above method returns string.

Example: 1#




// Scala program of substring()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying substring method
        val result = "GeeksforGeeks".substring(4, 8)
          
        // Displays output
        println(result)
      
    }

Output:

sfor

Example: 2#




// Scala program of substring()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying substring method
        val result = "GeeksforGeeks".substring(0, 4)
          
        // Displays output
        println(result)
      
    }

Output:

Geek

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!