Java - Write code to Subtract one string array from another

Requirements

Write code to Subtract one string array from another

Demo

//package com.book2s;
import java.util.*;

public class Main {
    public static void main(String[] argv) {
        String[] input = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        String[] list = new String[] { "1",  };
        System.out/* w ww . j a  v a 2s.  c  o  m*/
                .println(java.util.Arrays.toString(subtract(input, list)));
    }

    /**
     * Subtract one string array from another
     *
     * @param input Array elements to subtract
     * @param list  List to subtract from
     *
     * @return string array of merged set
     */
    public static String[] subtract(final String[] input,
            final String[] list) {
        final Set<String> difference = new HashSet<String>(
                Arrays.asList(list));
        difference.removeAll(Arrays.asList(input));
        return difference.toArray(new String[difference.size()]);
    }
}

Related Exercise