Java - Write code to get the index of Difference

Requirements

Write code to get the index of Difference

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str1 = "book2s.com";
        String str2 = "book2s.com";
        System.out.println(indexOfDifference(str1, str2));
    }/*www  . jav  a2s  .  com*/

    public static int indexOfDifference(String str1, String str2) {
        if ((str1 == null) || (str2 == null) || (str1.equals(str2))) {
            return -1;
        }

        int i;

        for (i = 0; (i < str1.length()) && (i < str2.length()); ++i) {
            if (str1.charAt(i) != str2.charAt(i)) {
                break;
            }
        }

        if ((i < str2.length()) || (i < str1.length())) {
            return i;
        }

        return -1;
    }

}