import java.util.*; public class JoinArrays { public static void main(String[] args) { int[] arr1 = {8, 2, 6, 4}; int[] arr2 = {9, 1, 5, 3, 7}; Set set = new TreeSet<>(); for (int num : arr1) set.add(num); for (int num : arr2) set.add(num); for (int num : set) { System.out.print(num + " "); } } }