Here you can find the source of difference(String str1, String str2)
Parameter | Description |
---|---|
str1 | a String. |
str2 | a String. |
public static int difference(String str1, String str2)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt public class Main { /**/*from w w w . j a v a 2 s .c o m*/ * Returns the number of characters in the two Strings that are the same. * * @param str1 a String. * @param str2 a String. * @return The number of characters in the two Strings that are the same. * */ public static int difference(String str1, String str2) { if (str1 == null || str2 == null) { return 0; } int lengthToMatch = Math.min(str1.length(), str2.length()); int diff = 0; for (int i = 0; i < lengthToMatch; i++) { if (str1.charAt(i) == str2.charAt(i)) { diff++; } } return diff; } }