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 // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying startsWith method val result = "GeeksforGeeks".startsWith("Geeks") // Displays output println(result) } } |
chevron_right
filter_none
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("geeks") // Displays output println(result) } } |
chevron_right
filter_none
Output:
false
Recommended Posts:
- Scala String startsWith(String prefix, int toffset) method with example
- Scala String indexOf(String str) method with example
- Scala String lastIndexOf(String str, int fromIndex) method with example
- Scala String indexOf(String str, int fromIndex) method with example
- Scala String regionMatches(int toffset, String other, int offset, int len) method with example
- Scala String lastIndexOf(String str) method with example
- Scala String split(String regex, int limit) method with example
- Scala String contentEquals() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala String subSequence() method with example
- Scala String equalsIgnoreCase() method with example
- Scala String endsWith() method with example
- Scala String compareToIgnoreCase() method with example
- Scala String charAt() method with example
- Scala String equals() method with example
- Scala String compareTo() method with example
- Scala String getBytes() method with example
- Scala String hashCode() method with example
- Scala String indexOf() method with example
- Scala String indexOf(int ch, int fromIndex) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

