Here you can find the source of intersection(String[] ary1, String[] ary2)
public static String[] intersection(String[] ary1, String[] ary2)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static String[] intersection(String[] ary1, String[] ary2) { List<String> list1 = new ArrayList<String>(Arrays.asList(ary1)); List<String> list2 = new ArrayList<String>(Arrays.asList(ary2)); list1.retainAll(list2);//from w w w . j ava2s . co m return list1.toArray(new String[0]); } }