java中如何将字符串数组转换成字符串

xiaoxiao2021-02-28  44

如果是 “字符串数组” 转 “字符串”,只能通过循环,没有其它方法

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

 

如果是 “字符数组” 转 “字符串” 可以通过下边的方法

char[] data={'a','b','c'}; String s=new String(data); String[] str = {"abc", "bcd", "def"}; StringBuffer sb = new StringBuffer(); for(int i = 0; i < str.length; i++){ sb. append(str[i]); } String s = sb.toString();

如果是 “字符数组” 转 “字符串” 可以通过下边的方法 

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

 

转载请注明原文地址: https://www.6miu.com/read-2626103.html

最新回复(0)