Java中把一个字符串实现反转
/** * 使用StringBuilder的reverse()方法将字符串反转 */ public static void main(String[] args) { StringBuilder sb = new StringBuilder("ABCDE牛"); System.out.println(sb.reverse()); }
public static String reverseTestThree(String s) { StringBuffer sb = new StringBuffer(); for (int i = s.length() - 1; i >= 0; i--) { sb.append(s.charAt(i)); } return sb.toString(); }
public static String reverseTestSix(String s) { if (s.length() <= 1) { return s; } return reverseTestSix(s.substring(1)) + s.substring(0, 1); }
标签:sir,Java,String,StringBuilder,static,sb,多测师,杭州 From: https://www.cnblogs.com/xiaoshubass/p/16980740.html