The Java code is here to merge and compare.
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.io.*;
- public class MergeCompare {
- public static void main(String args[]) throws Exception {
- BufferedReader br = new BufferedReader(new InputStreamReader(System. in ));
- System.out.println("1-Want to merge two arrays..?");
- System.out.println("2-Want to compare two arrays..?");
- System.out.println();
- System.out.print("Select any option: ");
- int select = Integer.parseInt(br.readLine());
- switch (select) {
- case 1:
- String a[] = {
- "S", "U", "N"
- };
- String b[] = {
- "D", "A", "Y"
- };
- List list = new ArrayList(Arrays.asList(a));
- list.addAll(Arrays.asList(b));
- Object[] c = list.toArray();
- System.out.println(Arrays.toString(c));
- break;
- case 2:
- int[] arr1 = {
- 1, 2, 3, 4, 5, 6, 6
- };
- int[] arr2 = {
- 1, 2, 3, 4, 5, 6, 6
- };
- int[] arr3 = {
- 1, 2, 3
- };
- System.out.println("Is array 1 equal to array 2?? " + Arrays.equals(arr1, arr3));
- System.out.println("Is array 1 equal to array 3?? " + Arrays.equals(arr1, arr2));
- break;
- }
- }
- }
Thank you, keep learning and sharing.