String 內存地址對比

public class Test {
public static void main(String[] args) {
String s = “abcdefg”;
String m = new String(“abcdefg”);
String n = “abcdefg”;
System.out.println(System.identityHashCode(s));
System.out.println(System.identityHashCode(m));
System.out.println(System.identityHashCode(n));
//s和n的內存地址一樣 m與他倆的內存地址不一樣
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章