StringBuilder与String相互转化

package com.daxing_01;

public class StringBuiderDemo02 {
public static void main(String[] args) {
//StringBuilder转化为String
StringBuilder st = new StringBuilder();
st.append("hello");
String s = st.toString();
System.out.println(s);

//String转化为StringBuilder
String r="hello";
StringBuilder sb = new StringBuilder(r);
System.out.println(sb);
}
}

输出:

hello
hello

Process finished with exit code 0

上一篇:代码优化


下一篇:反转字符串中的单词