[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/raskarabhi45/JavaCodes/main/StringXXXXX.java [Back]  [Original]

//string comparison
import java.io.*;

class StringXXXXX
{
    public static void main(String a[])
    {
        String str1="Hello";
        String str2="Hello";
        String str3= new String("Hello");

        if(str1==str2) //if(100==100) comparing references that is hash code
        {
            System.out.println("Strings are same");
        }
        else
        {
            System.out.println("Strings are different");
        }
        //inbuilt data for data comparison
        //this one is always better
        if(str1.equals(str2))  //if("Hello".equals("Hello"))
        {
            System.out.println("Strings are same");
        }
        else
        {
            System.out.println("Strings are different");
        }

        if(str1==str3) //if(100==100) comparing references that is hash code
        {
            System.out.println("Strings are same");
        }
        else
        {
            System.out.println("Strings are different");
        }

    }
}

Web Proxy Viewer  |  New URL  |  Original Page