java中我想把俩个都有空字符串的数组用for循环拼接到一个新的数组中,求大神指点 10
String[]a=newString[]{"1","2","3","","","free8"};String[]b=newString[]{"","","","4","...
String[] a = new String[]{"1","2","3","","","free8"};
String[] b = new String[]{"","","","4","5","free8"};
我想得到的结果是
String[] c = new String[]{"1","2","3","4","5","free8"}; 展开
String[] b = new String[]{"","","","4","5","free8"};
我想得到的结果是
String[] c = new String[]{"1","2","3","4","5","free8"}; 展开
2个回答
展开全部
public class CombinationArray {
public static void main(String[] args) {
/** 如果你要插入的数据位置是1对1的,那么可以取其中一个数组作为基本,另个数组的数据往里插 */
String[] a = new String[] { "1", "2", "3", "", "", "free8" };
String[] b = new String[] { "", "", "", "4", "5", "free8" };
for(int i = 0; i < a.length; i++){
if(a[i].equals("")){
a[i] = b[i];
}
}
System.out.println(java.util.Arrays.toString(a));
}
}
public static void main(String[] args) {
/** 如果你要插入的数据位置是1对1的,那么可以取其中一个数组作为基本,另个数组的数据往里插 */
String[] a = new String[] { "1", "2", "3", "", "", "free8" };
String[] b = new String[] { "", "", "", "4", "5", "free8" };
for(int i = 0; i < a.length; i++){
if(a[i].equals("")){
a[i] = b[i];
}
}
System.out.println(java.util.Arrays.toString(a));
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-11
展开全部
声明一个新的数组,然后把不是空的数据放到里面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询