Step 1- Create two array
Step 2- Convert these arrays into List
Step 3- Add second List into first List into resultant third List
Step 4- Convert the third list into Array.
Example –
AddTwoArray.java
Output:
A
E
I
O
U
1 2 | String a0[] = { "A", "E", "I" }; String b0[] = { "O", "U" }; |
Step 2- Convert these arrays into List
1 2 | List a1 = new ArrayList(Arrays.asList(a0)); List b1 = new ArrayList(Arrays.asList(b0)); |
Step 3- Add second List into first List into resultant third List
1 | a1.addAll(b1); |
Step 4- Convert the third list into Array.
1 | Object[] c = a1.toArray(); |
Example –
AddTwoArray.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package com.atozjavatutorials; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class AddTwoArray { public static void main(String arg[]){ String a0[] = { "A", "E", "I" }; String b0[] = { "O", "U" }; List a1 = new ArrayList(Arrays.asList(a0)); List b1 = new ArrayList(Arrays.asList(b0)); a1.addAll(b1); Object[] c = a1.toArray(); //System.out.println(a1); for (int i = 0; i < c.length; i++) { System.out.println(c[i]); } } } |
Output:
A
E
I
O
U
No comments :
Post a Comment