Compare strings for Equal - Java java.lang

Java examples for java.lang:String Compare

Introduction

The following code shows how to strings Equal.

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String s1 = "java2s.com";
        String s2 = "java2s.com";
        System.out.println(stringsEqual(s1, s2));
    }//  ww  w.j a  v a 2  s  . com

    public static boolean stringsEqual(String s1, String s2) {
        if (s1 == null && s2 == null)
            return true;
        else
            return s1 != null && s1.equals(s2);
    }
}

Related Tutorials