the interconversion of String and StringBuilder

package com.itheima_03;
/*
 * StringBuilder和String的相互转换
 * 
 * StringBuilder -- String
 *         public String toString():通过toString()就可以实现把StringBuilder转成String
 * 
 * String -- StringBuilder
 *         StringBuilder(String str):通过构造方法就可以实现把String转成StringBuilder
 */
public class StringBuilderTest {
    public static void main(String[] args) {
        //StringBuilder -- String
        /*
        StringBuilder sb = new StringBuilder();
        sb.append("hello").append("world");
        
        String s = sb.toString();
        System.out.println(s);
        */
        
        //String -- StringBuilder
        String s = "helloworld";
        StringBuilder sb = new StringBuilder(s);
        System.out.println(sb);
    }
}

 

posted @ 2018-10-09 21:15  小步快跑!!!!!  阅读(199)  评论(0编辑  收藏  举报