Java 字串 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 Tutorialspoint.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 Tutorialspoint.com Canonical representation: WELCOME TO SUTORIALSPOINT.COM
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP