Java - Write code to check if two string are equal using conditional operator

Requirements

Write code to check if two string are equal using conditional operator

check for null value.

Hint

conditional operator is like


condition ? value: value;

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s1 = "book2s.com";
        String s2 = "book2s.com";
        System.out.println(equals(s1, s2));
    }/*w w  w  .ja  va 2  s  .  c o m*/

    public static boolean equals(String s1, String s2) {
        return s1 == null ? s2 == null : s1.equals(s2);
    }
}