Open In App

Scala String startsWith(String prefix, int toffset) method with example

Last Updated : 29 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The startsWith(String prefix, int toffset) method is utilized to check if the stated string starts with the prefix or not that is being specified by us at the specified index.

Method Definition: Boolean startsWith(String prefix, int toffset)

Return Type: It returns true if the string starts with the specified prefix at the specified index else it returns false.

Example: 1#




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


Output:

true

Example: 2#




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


Output:

false


Similar Reads

Scala String regionMatches(int toffset, String other, int offset, int len) method with example
The regionMatches(int toffset, String other, int offset, int len) method is used to check if two string regions are equal or not. However, here ignoreCase is not included. Method Definition:Boolean regionMatches(int toffset, String other, int offset, int len) Return Type: It returns true if two string region matches else it returns false. Example #
1 min read
Scala String startsWith(String prefix) method with example
The startsWith(String prefix) method is utilized to check if the stated string starts with the prefix or not that is being specified by us. Method Definition: Boolean startsWith(String prefix) Return Type: It returns true if the string starts with the specified prefix else it returns false. Example: 1# // Scala program of startsWith() // method //
1 min read
Scala Int to(end: int, step: int) method with example
The to(end: int, step: int) method is utilized to return a range from the stated integer 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: Int, step: Int): Inclusive Return Type: It returns the range. Example #1: // Scala program of Int to() // method // Creating
1 min read
Scala Int until(end: Int, step: Int) method with example
The until(end: Int, step: Int) method is utilized to return a range from the start value to exact previous value of specified end integer value. Here the range's values are jumping by step value. Method Definition: defuntil(end: Int, step: Int): collection.immutable.Range Return Type: It returns the range. Example #1: // Scala program of Int until(
1 min read
Scala String substring(int beginIndex, int endIndex) method with example
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 dif
1 min read
Scala String indexOf(int ch, int fromIndex) method with example
The indexOf(int ch, int fromIndex) method is same as indexOf() method but here this method starts finding the character from the index we specify. Method Definition: int indexOf(int ch, int fromIndex) Return Type: It returns the index of the character specified in the argument. Example #1: // Scala program of int indexOf() // method // Creating obj
1 min read
Scala String lastIndexOf(int ch, int fromIndex)() method with example
The lastIndexOf() method is utilized to return the index of the last appearance of the character we specify in the argument from the index we specify for the stated string. Method Definition: int lastIndexOf(int ch, int fromIndex) Return Type: It returns the index of the last appearance of the character in the argument from the index we specify. Ex
1 min read
Scala Int /(x: Int) method with example
The /(x: Int) method is utilized to return the quotient when the specified first int value is divided by the second int value. Method Definition: (First_Int_Value)./(Second_Int_Value) Return Type: It returns the quotient when the specified first int value is divided by the second int value. Example #1: // Scala program of Int /(x: Int) // method //
1 min read
Scala Int !=(x: Int) method with example
The !=(x: Int) method is utilized to return true if the first int value is not equal to the specified second int value, otherwise returns false. Method Definition: (First_Int_Value).!=(Second_Int_Value) Return Type: It returns true if the first int value is not equal to the specified second int value, otherwise returns false. Example #1: // Scala p
1 min read
Scala Int %(x: Int) method with example
The %(x: Int) method is utilized to return the remainder when the specified first int value is divided by the second int value. Method Definition: (First_Int_Value).%(Second_Int_Value) Return Type: It returns remainder when the specified first int value is divided by the second int value. Example #1: // Scala program of Int %(x: Int) // method // C
1 min read