简单的实习如下,不知道还有没有更加高效的实现
- class Demo
- {
- public static void main(String[] args)
- {
- String str = "abcdefg";
- StringBuffer buf = new StringBuffer();
-
- //String >> StringBuffer
- buf.append(str);
-
- //StringBuffer >> String
- String str2 = buf.toString();
-
- System.out.println(buf);
- System.out.println(str2);
- }
- }
复制代码 |