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) |
---|---|
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.
}
}