Prints union of arr1 [ 0. . m - 1 ] and arr2 [ 0. . n - 1 ]
static void printUnion ( int arr1 [ ] , int arr2 [ ] ) { HashSet < Integer > hs = new HashSet < > ( ) ; for ( int i = 0 ; i < arr1 . length ; i ++ ) hs . add ( arr1 [ i ] ) ; for ( int i = 0 ; i < arr2 . length ; i ++ ) hs . add ( arr2 [ i ] ) ; System . out . println ( hs ) ; }