赞
踩
package MyString; /* StringBuilder和String的相互转换:转换后方便其转换后的调用方法 StringBuilder -- String public String toString():通过sb.toString()既可以实现把StringBuilder转化为String String -- StringBuilder StringBuilder(String str):通过构造方法StringBuilder sb = new StringBuilder(s);实现转化 */ public class StringBuilderToString { public static void main(String[] args) { //StringBuilder -- String StringBuilder sb = new StringBuilder(); sb.append("hello").append(123); String s = sb.toString(); System.out.println("s:"+s); //String -- StringBuilder String s1 = "超人强777"; StringBuilder sb1 = new StringBuilder(s1); System.out.println("sb1:"+sb1); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。