String使用注意一
生活随笔
收集整理的這篇文章主要介紹了
String使用注意一
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
public class StringNote{
?public static void main(String[] args){
??char[] c={'h','e','l','l','o'};
??String str1=new String(c);
??String str2=new String(c);
??String str3="hello";?//常量池中有 “hello” 字符串,str3和str4分別指向他
??String str4="hello";
??String str5=new String("hello"); //該對象是new出來的,因此是在堆內(nèi)存中而不是常量池中的“hello”字符串
??System.out.println(str1==str2);?//false
??System.out.println(str1==str3);?//false
??System.out.println(str3==str4);?//true
??System.out.println(str4==str5);?//false
?
?}
}
總結(jié)
以上是生活随笔為你收集整理的String使用注意一的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 地下城与勇士假野猪任务在哪儿接
- 下一篇: String使用注意二