Java intern () method
intern () method returns a string representation of the object of standardization.
It follows these rules: For any two strings s and t, if and only if s.equals (t) is true, s.intern () == t.intern () to be true.
grammar
public String intern()
parameter
no
return value
A string with the contents of this strings are the same, but it must have taken from the pool of unique strings.
Examples
public class Test { public static void main(String args[]) { String Str1 = new String("www.w3big.com"); String Str2 = new String("WWW.w3big.com"); System.out.print("规范表示:" ); System.out.println(Str1.intern()); System.out.print("规范表示:" ); System.out.println(Str2.intern()); } }
The above program execution results:
规范表示:www.w3big.com 规范表示:WWW.w3big.com