Home > Java > javaTutorial > body text

Java Example - Array Merging

黄舟
Release: 2017-02-18 10:10:05
Original
1658 people have browsed it

The following example demonstrates how to merge two arrays into one array through the Arrays.toString () method of the List class and the list.Addall(array1.asList(array2) method of the List class:

/*
 author by w3cschool.cc
 文件名:Main.java
 */import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Main {
   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));
   }}
Copy after login

Above The output result of running the code is:

[A, E, I, O, U]
Copy after login

The above is the content of Java instance-array merging. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!