Collection<TreeElement> () { Collection<TreeElement> result = new LinkedHashSet<>(); for (TreeElement object : myChildren) { if (object.toString().contains(myString)) { result.add(object); } } return result; }