对于任何两个字符串 s 和 t ,当且仅当s.equals(t)为s时,s.intern()== t.intern()才为true。
String intern() - 语法
这是此方法的语法-
public String intern()
String intern() - 返回值
- 此方法返回字符串对象的规范表示形式。
String intern() - 示例
import java.io.*; public class Test { public static void main(String args[]) { String Str1=new String("Welcome to Learnfk.com"); String Str2=new String("WELCOME TO SUTORIALSPOINT.COM"); System.out.print("Canonical representation:" ); System.out.println(Str1.intern()); System.out.print("Canonical representation:" ); System.out.println(Str2.intern()); } }
这将产生以下输出-
Canonical representation: Welcome to Learnfk.com Canonical representation: WELCOME TO SUTORIALSPOINT.COM