Java intern() 方法
intern() 方法返回字串對象的規範化表示形式。
它遵循以下規則:對於任意兩個字串 s 和 t,當且僅當 s.equals(t) 為 true 時,s.intern() == t.intern() 才為 true。
語法
public String intern()
參數
無
返回值
一個字串,內容與此字串相同,但一定取自具有唯一字串的池。
實例
public class Test { public static void main(String args[]) { String Str1 = new String("www.xuhuhu.com"); String Str2 = new String("WWW.xuhuhu.com"); System.out.print("規範表示:" ); System.out.println(Str1.intern()); System.out.print("規範表示:" ); System.out.println(Str2.intern()); } }
以上程式執行結果為:
規範表示:www.xuhuhu.com 規範表示:WWW.xuhuhu.com