Java String intern()方法示例。
String类的 intern()方法返回字符串对象的规范表示。因此,对于任意两个字符串s和t,当且仅当s.equals(t)为true时,s.intern()==t.intern()为true。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str1 = new String("Welcome to Nhooo.com");
String Str2 = new String("WELCOME TO SUTORIALSPOINT.COM");
System.out.print("规范表示:" );
System.out.println(Str1.intern());
System.out.print("规范表示:" );
System.out.println(Str2.intern());
}
}输出结果
规范表示: Welcome to Nhooo.com 规范表示: WELCOME TO SUTORIALSPOINT.COM