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 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