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

后端 未结 10 2074
闹比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:29

    String is non-primitive because only class can have methods. Primitive can not. And String need many functions to be called upon while processing like substring, indexof, equals, touppercase. It would not have been possible without making it class.

    Also class has made it possible to make strings immutable and final to enhance security and efficiency by allowing pooling.

提交回复
热议问题