Learning java - interception method string

/ *
String interception method:

public String substring (int index): the parameters taken from a position aligned to the end of the string, returns the new string.
public String substring (int begin, int end): begin taken from the start until the end of End, intermediate string.
Note: [begin, end), containing the left and the right are not included.
* /

public class Demo03Substring {
    public static void main(String[] args) {
        String str1 = "HelloWorld";
        String str2 = str1.substring(5);
        System.out.println(str1); // HelloWorld,原封不动
        System.out.println(str2); // World,新字符串
        System.out.println("================");

        String str3 = str1.substring(4,7);
        System.out.println(str3); // oWo
        System.out.println("================");

        // 下面这种写法,字符串的内容仍然是没有改变的
        // 下面有两个字符串:"Hello","Java"
        // strA当中保存的是地址值。
        // 本来地址值是Hello的0x666,
        // 后来地址值变成了Java的0x999
        String strA = "Hello";
        System.out.println(strA); // Hello
        strA = "Java";
        System.out.println(strA); // Java
    }
}
Published 23 original articles · won praise 0 · Views 157

Guess you like

Origin blog.csdn.net/qq_44813352/article/details/104314196