StringArrayUtil { public static String[] filterBySubstring(String[] strings, String substring) { ArrayList<String> result = new ArrayList<>(strings.length); int count = 0; for (String s : strings) { if (s.contains(substring)) { result.add(s); count++; } } return result.toArray(new String[count]); } protected  StringArrayUtil(); static String[] filterBySubstring(String[] strings, String substring); static String[] substringBefore(String[] strings, String separator); static int[] indicesOf(String[] strings, String substring);  }
@Test public void filterBySubstring() { assertThat( StringArrayUtil.filterBySubstring(new String[]{"aa", "ab", "ba", "aba", "cc"}, "b"), is(new String[] {"ab", "ba", "aba"})); }