Skip to content

Instantly share code, notes, and snippets.

@gauravkukade
Created August 25, 2019 11:33
Show Gist options
  • Save gauravkukade/55e93858fd88e8e3856bd108721016dd to your computer and use it in GitHub Desktop.
Save gauravkukade/55e93858fd88e8e3856bd108721016dd to your computer and use it in GitHub Desktop.
A java program to compare the reference of the strings. We use '==' operator to check the reference equality. Visit the detailed article about Java String pool and 'intern()' method https://coderolls.com/java-string-pool-and-intern-method
/**
* A java program to compare the reference of the strings.
* We use '==' operator to check the reference equality.
*
* @author Gaurav Kukade at coderolls.com
*
*/
public class StringReferenceCompare {
public static void main(String[] args) {
String firstString = "coderolls";
String secondString = "coderolls";
System.out.println(firstString == secondString); //true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment