system.out.println(s == s1);
// string 類 equals 重寫(比較的內容)
system.out.println(s.equals(s1));
// 字串是常量,它們的值在建立之後不能更改
// 一旦修改字串儲存的資料 自動建立乙個的物件內部儲存是修改的資料
string s2 = "abc";//new string("abc")
system.out.println(s2);
// string 把equals() 同時hashcode() 重新 都是內容相關
s2+=「def」;//new string(「abcdef」) 重新new乙個物件,把新的空間位址給s2
system.out.println(s2);
// string 不變性(改變後會建立新的物件)
// string 類,效能不高
// byte by = ;
// string b = new string(by);
// system.out.println(b);
// string bs = new string(by,0,3);
// system.out.println(bs);
string s4 = "gsdvukj";
char i = s4.charat(5);
system.out.println(i);
system.out.println(s4.compareto("gsduvbdkj"));
// s4.compareto(「iuafdk」); 大於1 小於-1 等於0
//拼接字串
system.out.println(s4.concat(「abc」));
string s5 = "kwesjbdv";
boolean bool = s5.contains("jd");
system.out.println(bool);
system.out.println(s5.endswith("bdv"));
system.out.println(s5.startswith("kw"));
string s6 = "abcdefg";
// 把字串轉換為位元組數
byte by = s6.getbytes();
for(int j = 0;j// 查詢字串中指定的字串的開始位置(找不到 返回 -1)
// 返回找到的乙個匹配到的位置
int index = s7.indexof(「d」);
system.out.println(index);
//字串常量池(起快取的作用)
// 把abc儲存到快取
string s8 = 「abc」;
// new 乙個字串 一定在堆區開闢空間儲存的abc(同時也會向快取中儲存abc)
// s9 指向堆區中new 的空間
string s9 = new string(「abc」);
system.out.println(s8 == s9);
// s9.intern() 返回對於快取中的abc的位址
system.out.println(s8==s9.intern());
// 字串常量池
java字串常量池
字串常量池,程式當中直接寫上雙引號字串,就在字串常量池中 對於基本型別來說 是進行數值得比較 對於引用型別來說 是進行 位址值 比較 string s1 abc string s2 abc system.out.println s1 s2 結果是 true 採用字面值的方式建立乙個字串時,jvm首先...
字串常量池
string的不可變性。字串常量池是不會儲存相同內容的字串。xx stringtablesize設定stringtable的長度。jdk8最小值為1009 string的string pool是固定大小的hashtable 字串常量池在堆中。字串拼接操作 和 equals equals 對於obje...
字串常量池
string a hello string b hello string aa new string aa string bb new string bb 字串常量池在方法區中 其中 變數a jvm先到字串常量池中尋找如果沒有就在字串常量池中建立乙個字串hello,並且將該字串常量池的hello的記...