StringArrayUtil { public static int[] indicesOf(String[] strings, String substring) { int[] result = new int[strings.length]; int count = 0; for (int i = 0; i < strings.length; i++) { String s = strings[i]; if (s.contains(substring)) { result[count++] = i; } } return Arrays.copyOf(result, 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 indicesOf() { assertThat( StringArrayUtil.indicesOf(new String[]{"foo", "g1.one", "g2.two", "bar"}, "."), is(new int[]{1, 2})); }
@Test public void indicesOfNoMatch() { assertThat( StringArrayUtil.indicesOf(new String[]{"foo", "g1.one", "g2.two", "bar"}, "z"), is(new int[] {})); }