union two string array - Android java.lang

Android examples for java.lang:array union merge

Description

union two string array

Demo Code


import java.util.LinkedList;

public class Main {

  public static String[] union(String[] a, String[] b) {
    LinkedList<String> retval = new LinkedList<String>();
    for (int i = 0; i < a.length; i++) {
      retval.add(a[i]);/*from ww w .  j  av a2  s  .  c o  m*/
    }

    for (int i = 0; i < b.length; i++) {
      if (!retval.contains(b[i])) {
        retval.add(b[i]);
      }
    }

    String[] retarray = new String[retval.size()];
    retval.toArray(retarray);
    return retarray;

  }

}

Related Tutorials