/**
* string 既可以作为基本数据类型
* 也可以作为引用数据类型
* @author 逸川同学
*
*/
public class MyString {
public static void main(String[] args) {
//1,string作为基本数据类型
/*
* 此时数据放在栈中,可以进行共享,不可以进行修改
*/
String s1 = "asd123";
s1 = s1+"qqq";
System.out.println(s1);
String s2 = s1;
System.out.println(s2);
//2,string作为引用数据类型
/*
* 此时数据放在堆当中,堆中的数据的地址放在栈中,数据可以修改但不可以共享
*/
String str1 = new String();
str1 = "xxx";
String str2 = new String();
str2 = str1;
System.out.println(str2);
str2 = "yyy";
System.out.println(str1);
System.out.println(str2);
/*
* 以上输出:
asd123qqq
asd123qqq
xxx
xxx
yyy
*/
}
}
java 中特殊的数据类型--string
最新推荐文章于 2023-02-06 00:16:50 发布