Java - Write code to compare two string for equal and handle null value using conditional operator

Requirements

Write code to compare two string for equal and handle null value using conditional operator

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String target1 = "book2s.com";
        String target2 = "book2s.com";
        System.out.println(equals(target1, target2));
    }//from www  .  jav a 2  s.  c o m

    public static boolean equals(final String target1, final String target2) {
        return (target1 == null) ? (target2 == null) : target1
                .equals(target2);
    }
}

Related Exercise