Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




subSequence() FUNCTION


subSequence() Function


The subSequence() Function is used to return a new string starting from the start and end index.


Example :



fun main() {

    var x = "Hello Girl"
    var y = x.subSequence(6, 10)
    println(y)
}


Output :



 Girl

In the above code, we have declared a String 'Hello Girl'.


var x = "Hello Girl"

java_Collections

Now, we will extract the substring 'Girl' from the String 'Hello Girl'.


So, we have used the 'subSequence()' to extract the substring 'Girl'.


var y = x.subSequence(6, 10)

java_Collections

So, the substring 'Girl' starts from index/position '6' to '9'. But to extract 'Girl',we have used '6' to '10'(And not '9').


var y = x.subSequence(6, 10)

Looks little weird?


Well! This is how it is.


Just remember, the end index should be the (End index value + 1). i.e. The end index for 'Girl' is '9' but we have used '10'.