对于任何两个字符串 s 和 t ,当且仅当s.equals(t)为s时,s.intern()== t.intern()才为true。
这是此方法的语法-
public 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()); } }
这将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/java/java-string-intern.html
来源:LearnFk无涯教程网
Canonical representation: Welcome to Learnfk.com Canonical representation: WELCOME TO SUTORIALSPOINT.COM
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)