Java 字符串反转:使用 StringBuilder 实现
可以使用 StringBuilder 的 reverse() 方法来实现字符串反转,然后将结果输出。以下是一个示例程序:
public class ReverseString {
public static void main(String[] args) {
String str = 'Hello, world!';
StringBuilder sb = new StringBuilder(str);
sb.reverse();
System.out.println(sb.toString());
}
}
输出结果为:!dlrow ,olleH
原文地址: https://www.cveoy.top/t/topic/ov6e 著作权归作者所有。请勿转载和采集!