Question Index

Write a program to get the union of two arrays. The output array should be sorted.
Assume that there are no duplicates in individual arrays.

Input(First Array, Second Array) Output(Sorted Union Array)
{"Lion", "Tiger", "Black Bear", "Camel", "Elephant", "Leopard"} and {"Dog", "Cat", "Goat", "Rabbits"} {Black Bear, Camel, Cat, Dog, Elephant, Goat, Leopard, Lion, Rabbits, Tiger}
{"Andhra Pradesh", "Karnataka", "Kerala", "TamilNadu"} and {"Delhi", "Haryana ", "Himachal Pradesh ", "Jammu and Kashmir", "Uttarakhand", "Punjab", "Uttar Pradesh"} {Andhra Pradesh, Delhi, Haryana, Himachal Pradesh, Jammu and Kashmir, Karnataka, Kerala, Punjab, TamilNadu, Uttar Pradesh, Uttarakhand}

class UnionOfTwoArrays

{    public static void main(String s[])
        String firstArray[] = {"Sachin Tendulkar", "Dhoni", "Sehwag", "Yuvraj Singh", "Virat Kohli", "Gautam Gambhir"};
        String secondArray[] = {"Zaheer Khan", "Irfan Pathan", "Harbhajan Singh", "Ashwin", "Nehra", "Agarkar", "Munaf Patel", "Balaji"};
        String resultantArray[] = sortedUnionArray(firstArray, secondArray);
        System.out.print("The resultant array is ");
        for(String str : resultantArray)
        System.out.print(str + ", ");


public static String[] sortedUnionArray(String firstSeries[], String secondSeries[])
//write a code here to concate the two string arrays and return it.If required, you can use sortingArray method.
public static String[] sortingArray(String resultArray[])
//write a code here to sort the result array and return it.



Topic: Java String Arrays - String Arrays In Java

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App