java中字符串反转的几种写法

#### 代码如下
```java
package pers.mine.scratchpad.other;

import org.junit.Test;

/**
 * java 反转字符串的几种写法
 * @author Mine
 * @date 2019/06/24 01:03:06
 */
public class StringReverseTest {
	String s = "ABCDE";
	/**
	 * StringBuffer
	 */
	@Test
	public void testA() {
		System.out.println(new StringBuffer(s).reverse());
	}
	
	/**
	 * StringBuilder
	 */
	@Test
	public void testB() {
		System.out.println(new StringBuilder(s).reverse());
	}
	
	/**
	 * toCharArray()
	 */
	@Test
	public void testC() {
		char[] chars = s.toCharArray();
		for (int i = 0; i < chars.length; i++) {
			System.out.print(chars[chars.length-1-i]);
		}
		System.out.println();
	}
	/**
	 * charAt()
	 */
	@Test
	public void testD() {
		int length = s.length();
		for (int i = 0; i < length; i++) {
			System.out.print(s.charAt(length-1-i));
		}
		System.out.println();
	}
}

```
#### 代码地址
[GitHub](https://github.com/yebukong/scratchpad/blob/master/src/test/java/pers/mine/scratchpad/other/StringReverseTest.java "GitHub")
[Gitee](https://gitee.com/yebukong/scratchpad/blob/22ef9de9dac450a78ece0bdd3926e85e137119e3/src/test/java/pers/mine/scratchpad/other/StringReverseTest.java "Gitee")

------------
> 本文由 [叶不空](https://yebukong.com "叶不空") 创作,采用 [知识共享署名 4.0 国际许可协议](https://creativecommons.org/licenses/by/4.0/ "知识共享署名 4.0 国际许可协议")进行许可,转载请附上链接!
> 本文链接: [https://yebukong.com/article/1142846108897165313.html](https://yebukong.com/article/1142846108897165313.html "java中字符串反转的几种写法")
                        
(°ο°)评论插件未能完成加载!