Please explain this method and use of this method to print subsequence like Hl from the string of Hello
subSequence() method in string
Hi Sumit
subSequence() method is a built-in method under the String class that returns a character subsequence of the string object instance on which it is applied. It takes two input parameters: start index and end index and returns the subsequence from startindex to endindex-1
However the example you have mentioned of extracting Hl from Hello can not be done using this method as Hl is definitely a sub sequence of Hello but that is not what subSequence function does. It returns a contiguous sequence from indexes mentioned above. This is due to Java name classification being different than actual implementation.
However it is still different than substring in that it does not return a string, hence cannot be stored in another variable but can only be printed.
So system.out.print(String.subSequence(0,10)) would work whereas String var = String.subSequence(0,10) would not
thank you