Merge arrays using lists
•
Java
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
public class array_merge {
public static void main(String[] args) {
//利用列表合并
String a[]={"A","E","I"};
String b[]={"O","U"};
List list=new ArrayList(Arrays.asList(a));
list.addAll(Arrays.asList(b));
Object[] c=list.toArray();
System.out.println(Arrays.toString(c));
//通过数组合并
String d[]=new String[a.length+b.length];
for(int i=0;i<a.length;i++){
d[i]=a[i];
}
for(int i=a.length;i<d.length;i++){
d[i]=b[i-a.length];
}
for(int i=0;i<d.length;i++){
if(i!=0){
System.out.print(",");
}
System.out.print(d[i]);
}
}
}
The output result is:
[A,E,I,O,U] A,U
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
