In Java, Why String is non-primitive data type?

后端 未结 10 2077
闹比i
闹比i 2021-01-01 03:10

In Java, we can directly use String to declare a string variable name and specify its value. We do not have to define the string as an array by using new keywor

10条回答
  •  借酒劲吻你
    2021-01-01 03:48

    String is object, is immutable, that means that you cannot change the object itself, but you can change the reference to the object.

    This is how String works

    String myStr = "test";
    

    This as usual, creates a string named "test" and assign it a reference "myStr".

    Important point to note here is, while the String object is immutable, its reference variable is not.

提交回复
热议问题