How string class difference from other classes?

后端 未结 4 709
不思量自难忘°
不思量自难忘° 2021-01-21 07:37

We can do:

String string = \"ourstring\";

But we can\'t create objects like this for user defined classes:

UserClass uc=\"\";

4条回答
  •  既然无缘
    2021-01-21 08:31

    For details on this topic, review the online Javadoc: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html

    Strings are nice in Java. They get the benefits of being used like primitives but are internally Objects. There is an internal "interned String pool" that keeps track of String objects for you. This is done primarily for efficiency's sake but the abstraction is neat enough that you can pretend that a String is just a primitive like an int or a char.

    Please remember to avoid creating a String manually using a constructor like you would most objects!

提交回复
热议问题