//import java.util.*; public class StringObject{ public static void main(String[] args) { String s1="OOPJ"; String s2="object oriented program"; String s3="OOPJ"; String s4=s3; String s5=new String("OOPJ"); String s6=new String("object oriented program"); System.out.println("s1 and s2 have same reference :"+(s1==s2)); System.out.println("s3 and s4 have same reference :"+(s3==s4)); System.out.println("s1 and s5 have same reference :"+(s1==s5)); System.out.println("s2 and s6 have same reference :"+(s2==s6)); System.out.println("s3 and s6 have same reference :"+(s3.equals(s5))); System.out.println("s2 and s6 have same reference :"+(s2.equalsIgnoreCase(s6))); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter