Compare two string for equal - Java java.lang

Java examples for java.lang:String Compare

Description

Compare two string for equal

Demo Code


public class Main{

    public static void main(String[] argv){
        String l = "java2s.com";
        String r = "java2s.com";
        System.out.println(equals(l,r));
    }/*from  w  ww  . ja v  a2  s .c o m*/
    public static boolean equals(String l, String r) {
        if (l != r) {
            if (l != null || r != null) {
                return l.equals(r);
            }
            return false;
        }
        return true;
    }
    public static boolean equals(String l, String r) {
        if (l != r) {
            if (l != null || r != null) {
                return l.equals(r);
            }
            return false;
        }
        return true;
    }

}

Related Tutorials