通过reverse实现字符串的旋转
public String reverseTarget(String str,int index){ StringBuilder qian = reverse(str.substring(0, index)); StringBuilder hou = reverse(str.substring(index)); String zong = ""+qian+hou; StringBuilder reverse2 = reverse(zong); return reverse2.toString(); } public StringBuilder reverse(String str) { StringBuilder sb = new StringBuilder(); for (int i = str.length()-1; i >= 0; i--) { sb.append(str.charAt(i)); } return sb; }