What is subSequence in Scala?

Scala offers many methods for string manipulation, the subSequence function being one of them. The subSequence function can be used to get a subsequence or a substring of a piece of text by specifying the starting and ending indices.

Syntax

CharSequence subSequence(int startIndex, int endIndex)

Parameters

The subSequence function takes two parameters:

  • startIndex: The index of the string where the subsequence will begin.
  • endIndex: The index of the string where the subsequence will end.

Return value

The subSequence function returns the substring between the starting and ending indices.

Code

The following code shows the implementation of subSequence function:

object Main extends App{
// using subSequence function
val sub_sequence = "This is an Edpresso shot".subSequence(11, 19)
// Displays subsquence
println(sub_sequence)
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved