判断一个字符串是否对称:
public static void main(String[] args) {
String string = "aaabbaaa";
StringBuffer str = new StringBuffer(string);
String s = str.reverse().toString();
System.out.println("通过stringbuffer的reverse方法判断字符串是否对称:结果为:"+s.equals(string));
char[] chars = string.toCharArray();
Boolean b = true;
for(int start = 0,end = chars.length-1;start<end;start++,end--){
if(chars[start] != chars[end]){
b = false;
}
}
System.out.println("通过字符数组的方式依次比较头尾字符,结果为:"+b);
}