Java中的string类型不是基本的数据类型。而是一个类,但是该类被final修饰过以后,是不能被继承的。而在Java中的基本数据类型只有8种:byte,int,short,long,float,doble,char,boolean. 举例说明string的用法: string类被设计成一个不可变的类(immutable)。string s=”hello”;s=s+”world”;原来的string对象的内容并没有发生变化,而是新开辟出一段内存来存储“hello world”。 stringbuffer是可变的。而string实现了equals方法而stringbuffer并没有实现。例如
new string(
"abc").
equals(
new string(
"abc"))返回值为
TRUE。
public class Test {
public static void main(String[] args) {
String s1=
"a";
String s2=
"b";
String s3=
"a"+
"b";
String s4=
"ab";
System.
out.println(s3==s4);
}
}
运行结果是TURE
转载请注明原文地址: https://ju.6miu.com/read-155367.html