判断两字符串相等java
2017-07-01 本文已影响0人
whiteList
//同一对象
if (s1 == s2) return true;
if (s1 == null || s2 == null) return false;
if (s1.length() == s2.length()) {
int n = s1.length();
int i = 0;
char[] s1Arr = s1.toCharArray();
char[] s2Arr = s2.toCharArray();
while (i < n) {
//忽略大小写
if (Character.isLetter(s1Arr[i]) && Character.isLetter(s2Arr[i])) {
s1Arr[i] = Character.toLowerCase(s1Arr[i]);
s2Arr[i] = Character.toLowerCase(s2Arr[i]);
}if (s1Arr[i] != s2Arr[i]) {
return false;
}
i++;
}
return true;
}
return false;
}```