Java intern() 方法
Java 教程
· 2019-02-08 22:27:58
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.codercto.com");
String Str2 = new String("WWW.CODERCTO.COM");
System.out.print("规范表示:" );
System.out.println(Str1.intern());
System.out.print("规范表示:" );
System.out.println(Str2.intern());
}
}
以上程序执行结果为:
规范表示:www.codercto.com 规范表示:WWW.CODERCTO.COM
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
Fluent Python
Luciano Ramalho / O'Reilly Media / 2015-8-20 / USD 39.99
Learn how to write idiomatic, effective Python code by leveraging its best features. Python's simplicity quickly lets you become productive with it, but this often means you aren’t using everything th......一起来看看 《Fluent Python》 这本书的介绍吧!