Java - Write code to compare two string value for equality with nested if statement

Requirements

Write code to compare two string value for equality with nested if statement

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str1 = "book2s.com";
        String str2 = "book2s.com";
        System.out.println(equals(str1, str2));
    }//ww w. java  2 s.c o m

    public static boolean equals(String str1, String str2) {
        if (str1 == null) {
            if (str2 != null) {
                return false;
            }
        } else if (!str1.equals(str2)) {
            return false;
        }

        return true;
    }
}

Related Exercise