public static void main(String[] args) {
String a = "aaa";
String b = "aaa";
//System.out.println(myEqualsStringTochar(a, b));
//System.out.println(myEqualsStringCompareTo(a, b));
System.out.println(myEqualsStringHashCode(a,b));
}
private static boolean myEqualsStringHashCode(String a, String b) {
if(a.hashCode()==b.hashCode()){
return true;
}else{
return false;
}
}
private static boolean myEqualsStringCompareTo(String a, String b) {
int flag = 0;
if (a != null && b != null) {
flag = a.compareTo(b);
}
if (flag == 0) {
return true;
}
return false;
}
private static boolean myEqualsStringTochar(String a, String b) {
int length = Math.max(a.length(), b.length());
char[] atemp = new char[length];
char[] btemp = new char[length];
a.getChars(0, a.length(), atemp, 0);
b.getChars(0, b.length(), btemp, 0);
boolean flag = true;
for (int i = 0; i < atemp.length; i++) {
char temp = atemp[i];
for (int j = 0; j < btemp.length; j++) {
if (btemp[j] == temp) {
flag = flag && true;
} else {
flag = false;
}
}
}
return flag;
}