可用字符串构造一 StringBuffer 对象,然后调用 StringBuffer 中的 reverse
方法即可实现字符串的反转,调用 replace 方法即可实现字符串的替换。
public class test {
public static void main(String[] args) {
StringBuffer sb=new StringBuffer("hello");
System.out.println(sb);
sb.reverse();
System.out.println(sb);
}
}
输出结果:
hello olleh