用equals比较两个相同的字符串,值总是false
public String test(String str) throws Exception {
char []temp=new char[100];
char []s=str.toCharArray();
for (int i=0;i<s.length;i++) {
char c=s[i];
if((c>='a'&&c<='z')||(c>='0'&&c<='9'))
temp[i]=c;
else if(c>='A'&&c<='Z')
{
c=(char)(c+32);
temp[i]=c;
}
}
String str1=new String(String.valueOf(temp).getBytes("ISO-8859-1"),"utf-8");
System.out.println(str1);
String str2=new String(new StringBuffer(str1).reverse().toString().getBytes("ISO-8859-1"),"utf-8");
System.out.println(str2);
System.out.println(str1.equals(str2));
if(str1==str2)
return "yes";
return "fail";
}
public static void main(String[] args) throws Exception {
System.out.println( new text().test("A man, a plan, a canal: Panama"));
}
将两个字符串的编码统一后还是false,在线求解。