public String getString(List<Integer> list) { if (list == null || list.isEmpty()) { return null; } list.removeIf(e -> isNotValid(e)); return list.stream().map(String::valueOf).collect(Collectors.joining(",")); } private static Boolean isNotValid(Integer in) { if (in == null) {//为空的为无效数字 return true; } return false; } //输入:[1,2,3,null,5,null,7] //输出:"1,2,3,5,7"