void (String[] args) { List<String> list = new ArrayList<>(); for (Iterator<String> it = new Test().names().iterator(); it.hasNext(); ) { String name = it.next(); String n = name.trim(); if (!n.isEmpty()) { list.add(n); } } }