Latest web development tutorials

Java instances - array merge

Java Examples Java Examples

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

/*
 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));
   }
}

The above code is run output is:

[A, E, I, O, U]

Java Examples Java Examples