List<T> (List<?> content) { if (content == null) { return Collections.emptyList(); } if (content instanceof RandomAccess) { int size = content.size(); List<T> result = new ArrayList<>(size); for (int i = 0; i < size; i++) { T c = filter(content.get(i)); if (c != null) { result.add(c); } } return result.isEmpty() ? Collections.emptyList() : result; } List<T> result = new ArrayList<>(); for (Object o : content) { T c = filter(o); if (c != null) { result.add(c); } } return result.isEmpty() ? Collections.emptyList() : result; }