How to check if two strings are equals using equals() in Java

2 Answers

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String s1 = "java";
            String s2 = "java";

            boolean b = s1.equals(s2);
            System.out.println(b);
            
            b = s1.equals("c++");
            System.out.println(b);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
true
false
  
 */

 



answered Nov 22, 2016 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String s1 = "java";
            String s2 = "JAva";

            boolean b = s1.equals(s2);
            System.out.println(b);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
           
run:
     
false
  
 */

 



answered Nov 22, 2016 by avibootz
...