字符数组、字符串数组转换成字符串【JAVA基础】

一、字符数组to字符串
直接声明

char[]  c={'a', 'b', 'c'};
 
String s = new String(c);

二、字符串数组to字符串
string是不可变类——利用StringBuffer

String[ ]  str = {"abc", "dfe", "hij"};
 
StringBuffer sb = new StringBuffer();
 
for(int i = 0; i < str.length;i++){
 
  sb.append(str[i]);
 
}
 
String s = sb.toString();

————————————————
版权声明:本文为CSDN博主「Ella7」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Ella7/article/details/81387094

原创文章 27 获赞 2 访问量 1131

猜你喜欢

转载自blog.csdn.net/liudachu/article/details/105609991