java tutorial - Java Strings intern() method - java programming - learn java - java basics - java for beginners

Learn Java - Java tutorial - Java strings intern - Java examples - Java programs
Description
The intern () method returns a canonical representation for a string object. It follows that for any two rows s and t, s.intern () == t.intern (), it is true if and only if s.equals (t) is true.
Syntax
Syntax method:
public String intern()
click below button to copy the code. By - java tutorial - team
Detailed information about the parameters:
- This method does not accept any parameters by default..
Return value
- In Java, intern () returns a canonical representation for a string object.
Sample Code
import java.io. *;
public class Test {
public static void main(String args []) {
String Str1 = new String("Welcome to wikitechy.com" );
String Str2 = new String("WELCOME TO wikitechy.com" );
System.out.print("Canonical representation of Str1:" );
System.out.println(Str1.intern());
System.out.print("Canonical representation of Str2:" );
System.out.println(Str2.intern());
}
}
click below button to copy the code. By - java tutorial - team
Output
Canonical representation of Str1:Welcome to wikitechy.com
Canonical representation of Str2:WELCOME TO wikitechy.com