StringUtil { public static String[] filterSystemArgs(String[] args) { ArrayList<String> whatsLeft = new ArrayList<String>(); for (String a : args) { if (a.startsWith("-D")) { String key; String value; int cut = a.indexOf('='); if (cut < 0) { key = a.substring(2); value = ""; } else { key = a.substring(2, cut); value = a.substring(cut + 1); } System.setProperty(key, value); } else { whatsLeft.add(a); } } return (String[]) whatsLeft.toArray(new String[whatsLeft.size()]); } private  StringUtil(); static String[] filterSystemArgs(String[] args); static String trimSuffix(String str, String suffix); static String join(Iterable<String> parts, String separator); static void toUpperCaseArray(String[] source, String[] target); static String noBlank(String str, String dft); static String dropSuffix(String str, String suffix); static String min(Collection<String> strs); static String max(Collection<String> strs); static String min(String s1, String s2); static String max(String s1, String s2); static String[] subArray(String[] array, int start, int endExclusive); static void appendWithSeparator(StringBuilder src, String append); static String[] splitAndTrim(String str, String splitBy); static String[] split(String str, String splitBy); static String[] splitByComma(String str); static int utf8Length(CharSequence sequence); static boolean equals(String a, String b);  }
@Test public void testFilterSystemArgsThrowsIllegalArgumentException() { String[] stringArray = new String[4]; stringArray[0] = "-D"; try { StringUtil.filterSystemArgs(stringArray); fail("Expecting exception: IllegalArgumentException"); } catch(IllegalArgumentException e) { } }
@Test public void testFilterSystemArgs() { String[] stringArray = new String[1]; stringArray[0] = "J"; String[] stringArrayTwo = StringUtil.filterSystemArgs(stringArray); assertFalse(stringArrayTwo.equals(stringArray)); assertEquals(1, stringArrayTwo.length); assertEquals("J", stringArrayTwo[0]); }