赞
踩
stringbuilder转换为string
.public string tostring();通过tostring,就可以实现把stringbuilder转换为string了
string转换为stringbuilder
.public stringbuilder(string s); 通过构造方法,就可以实现把string转换成stringbuilder了
- package 字符串;
-
- public class stringbuilder与string相互转换 {
-
- public static void main(String[] args) {
- // stringbuilder转换为string
-
- StringBuilder sb = new StringBuilder();
- sb.append("hello");
- String s = sb.toString();
- System.out.println(s);
- }
-
- }
- package 字符串;
-
- public class stringbuilder与string相互转换 {
-
- public static void main(String[] args) {
-
- // string转换为stringbuilder,通过构造方法实现,
-
- String s1 = "world";
- StringBuilder sb1 = new StringBuilder(s);
- System.out.println(sb1);
-
-
-
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。