strings.java

来自「主要是对于JAVA的编程的基本语言 希望能够帮得上你。」· Java 代码 · 共 32 行

JAVA
32
字号
package Operator;

/* 
 String objects are given special treatment by the Java language. 
 It is also important to differentiate how String objects behave
 when compared to regular objects. (字符串对象与普通对象之间的区别)
*/

class Strings {
    public static void main(String [] args) {
        String x = "Java";
        String y = x;
        System.out.println("y string = " + y);
        x = x + " Bean";
        System.out.println("y string = " + y);
    }
}

/*
 You might think String y will contain the characters Java Bean 
 after the variable x is changed, because strings are objects. 
 Let’s examine the output to find out:
 
 y string = Java
 y string = Java
  
 As you can see, even though y is a reference variable to the same object
 that x refers to, when we change x it does not change y. 
 This is because a brand new String object is created every time
 we use the + operator to concatenate two strings. 
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?