日期:2014-05-20 浏览次数:20804 次
public static boolean equels(String first , String second ) {
first = first.toLowerCase() ;
second = second.toLowerCase() ;
byte[] ch = first.getBytes() ;
byte[] ch1 = second.getBytes() ;
sort(ch);
sort(ch1);
return new String(ch).equals(new String(ch1));
}
private static void sort(byte[] ch) {
for(int i=0 ; i<ch.length-1 ; i++) {
int lag = ch[i];
int index = i ;
for(int j=i+1 ; j<ch.length ; j++) {
if(lag < ch[j]) {
lag = ch[j];
index = j ;
}
}
ch[index] = ch[i];
ch[i] = (byte) lag ;
}
}
public static int getHashCode(String str){
int h=0;
for(Character c:str.toUpperCase().toCharArray()){
h+=c.hashCode();
}
return h;
}
public static void main(String[]args)
{
System.out.println(getHashCode("abc")==getHashCode("aca"));
}
/**
* 思路
* 1.比较长度
* 2.source转换char数组,去desc匹配,然后删除。
* @param source
* @param desc
* @throws Exception
*/
public static void checkString(String source, String desc) throws Exception {
if (source.length() != desc.length()) {
System.out.println("not equal!");
return;
}
source = source.toLowerCase();
desc = desc.toLowerCase();
char[] sourceChars = source.toCharArray();
for (char sourceChar : sourceChars) {