public static String [ ] intersect ( String [ ] arr1 , String [ ] arr2 ) { Map < String , Boolean > map = new HashMap < String , Boolean > ( ) ; LinkedList < String > list = new LinkedList < String > ( ) ; for ( String str : arr1 ) { if ( ! map . containsKey ( str ) ) { map . put ( str , Boolean . FALSE ) ; } } for ( String str : arr2 ) { if ( map . containsKey ( str ) ) { map . put ( str , Boolean . TRUE ) ; } } for ( Entry < String , Boolean > e : map . entrySet ( ) ) { if ( e . getValue ( ) . equals ( Boolean . TRUE ) ) { list . add ( e . getKey ( ) ) ; } } String [ ] result = { } ; return list . toArray ( result ) ; }
Arr1 intersect Arr2