Java Array Sub Array sub(String[] a, String[] b)

Here you can find the source of sub(String[] a, String[] b)

Description

subtract b from a

License

Open Source License

Declaration

public static String[] sub(String[] a, String[] b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**/*from w w  w  .  j  a  v a  2  s.  c  o  m*/
     * subtract b from a
     */
    public static String[] sub(String[] a, String[] b) {
        // really inefficient...
        TreeSet<String> s = new TreeSet<>(Arrays.asList(a));
        s.removeAll(Arrays.asList(b));
        if (s.size() != a.length) {
            //System.out.println("sub: " + Arrays.toString(a) + " - " + Arrays.toString(b) + " = " + s);
            return s.toArray(new String[s.size()]);
        } else {
            return a;
        }
    }
}

Related

  1. sub(T[] source, int first, int last)
  2. subarray(boolean[] array, int fromIndex, int length)
  3. subArray(byte[] a, int beginIndex, int endIndex)
  4. subArray(byte[] array, int beginIndex, int endIndex)