intersection two String array - Android java.lang

Android examples for java.lang:array union merge

Description

intersection two String array

Demo Code

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Main {

  public static String[] intersection(String[] a, String[] b) {
    List<String> bList = Arrays.asList(b);
    LinkedList<String> retVal = new LinkedList<String>();

    for (int i = 0; i < a.length; i++) {
      if (bList.contains(a[i])) {
        retVal.add(a[i]);//from   w  w  w  . j a  v a  2 s .  co  m
      }
    }

    String[] retArray = new String[retVal.size()];
    retVal.toArray(retArray);
    return retArray;
  }

}

Related Tutorials