 <p>If the two string are of different size the following code you return the total mismatch of alphabets.</p> <p>You can try this - </p> <pre><code> String ip1 = "input"; // input1 String ip2 = "utput"; // input2 int count = 0; // difference in string String ipx2 = ip2; for (int j = 0; j &lt;= ip2.length(); j++) { int value = ip1.indexOf(ipx2); if (value != -1) { if (("").equals(ipx2)) { // if the second string is blank after continous reducing count = ip1.length() + ip2.length(); } else { count = ip1.length() + ip2.length() - 2 * ipx2.length(); } break; } else { count = ip1.length() + ip2.length(); // if there is no match at all } ipx2 = ip2.substring(j); } System.out.println("" + count); } </code></pre> <p>You will have to check whether the inputs have some data or not. I have not done that check.</p>