void (List<String> list) { List<Integer> result = new ArrayList<>(); for (String x : list) { if (x != null) { Predicate<Integer> predicate = Predicate.isEqual(x.length()); for (int i = 0; i < 10; i++) { Integer integer = i; if (predicate.test(integer)) { result.add(integer); } } } } System.out.println(result); }