Difference between subSequence and subString methods in java String class

I have a little confusion regarding the difference between the subSequence method and subString in the Java String class. I read the article What is the difference between String.subString () and String.subSequence () , which was answered on this question, but I have a little confusion, the article mentioned "I read it only in the sense that you cannot change characters in CharSequence without instantiating CharSequence .

But when I tried in the following example,

String string = "Hello";
CharSequence subSequence = string.subSequence(0, 5);
System.out.println(subSequence.subSequence(1, 4));
subSequence = subSequence.subSequence(1, 4);
System.out.println(subSequence);

he prints an
outbuilding
ell

I do not know if I understood this correctly. Could you help me clarify this and tell me the difference between subString and subSequence with an example

+4
3

, , . String, CharSequence.

, CharSequence - , String - , CharSequence.

, String CharSequence, . substring() CharSequence, :

String string = "Hello";

String subString1 = string.substring(1,4);             // ell
String subString2 = string.subSequence(1, 4);          // Type mismatch compiler error

CharSequence subSequence1 = string.subSequence(1, 4);  // ell
CharSequence subSequence2 = string.substring(1, 4);    // ell

, subSequence() String, String, substring():

public CharSequence subSequence(int beginIndex, int endIndex) {
    return this.substring(beginIndex, endIndex);
}

, , substring() subSequence() , String.


, , String, subSequence() substring() . , "" CharSequence, String , , .

CharSequence, , , String.

+9

" , CharSequence CharSequence.

, , , CharSequence :

CharSequence subSequence = string.subSequence(0, 5);
subSequence = subSequence.subSequence(1, 4);

, CharSequence . CharSequence. , .

0

: , subSequence, - . . , .

Modification is any operation on a line that will lead to another line, for example, adding or removing characters or changing characters.

-1
source

All Articles