Java intern() 方法
intern() 方法返回字符串對(duì)象的規(guī)范化表示形式。
它遵循以下規(guī)則:對(duì)于任意兩個(gè)字符串 s 和 t,當(dāng)且僅當(dāng) s.equals(t) 為 true 時(shí),s.intern() == t.intern() 才為 true。
語法
public String intern()
參數(shù)
無
返回值
一個(gè)字符串,內(nèi)容與此字符串相同,但一定取自具有唯一字符串的池。
實(shí)例
public class Test { public static void main(String args[]) { String Str1 = new String("m.o2fo.com"); String Str2 = new String("m.o2fo.com"); System.out.print("規(guī)范表示:" ); System.out.println(Str1.intern()); System.out.print("規(guī)范表示:" ); System.out.println(Str2.intern()); } }
以上程序執(zhí)行結(jié)果為:
規(guī)范表示:m.o2fo.com 規(guī)范表示:m.o2fo.com
更多建議: