List<Object> () { final TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) { return Collections.emptyList(); } List<Object> elements = new ArrayList<>(); for (TreePath selectionPath : selectionPaths) { final Object pathElement = getPathElement(selectionPath); if (pathElement != null) { elements.add(pathElement); } } return elements; }