Object[] (String[] input, boolean f) { List<String> list = Arrays.stream(input) .filter(Objects::nonNull) .<caret>collect(Collectors.toList()); String[] data = new String[] {}; if (f) { return list.toArray(); } list.add("hello"); return list.toArray(); }