Write code to Subtract one string array from another
//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//from w w w . j ava 2 s. c om .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()]); } }