两个String数组怎么合并成一个数组?
1个回答
2018-02-03 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
import java.util.Arrays;
//Java中如何把两个数组合并为一个
public class gog {
public static void main(String[] args) {
String [] str1 = {"J","a","v","a","中"};
String [] str2 = {"如","何","把","两","个","数","组","合","并","为","一","个"};
int strLen1=str1.length;//保存第一个数组长度
int strLen2=str2.length;//保存第二个数组长度
str1= Arrays.copyOf(str1,strLen1+ strLen2);//扩容
System.arraycopy(str2, 0, str1, strLen1,strLen2 );//将第二个数组与第一个数组合并
System.out.println(Arrays.toString(str1));//输出数组
}
}
//Java中如何把两个数组合并为一个
public class gog {
public static void main(String[] args) {
String [] str1 = {"J","a","v","a","中"};
String [] str2 = {"如","何","把","两","个","数","组","合","并","为","一","个"};
int strLen1=str1.length;//保存第一个数组长度
int strLen2=str2.length;//保存第二个数组长度
str1= Arrays.copyOf(str1,strLen1+ strLen2);//扩容
System.arraycopy(str2, 0, str1, strLen1,strLen2 );//将第二个数组与第一个数组合并
System.out.println(Arrays.toString(str1));//输出数组
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询