package js_ecu_app; import java.util.*; import java.util.stream.Collectors; public class test3 { public static void main(String[] args) { // HashSet<String> set = new HashSet<>(); // String num = "12,12,14"; // // String[] split = num.split(","); // for (String s : split) { // set.add(s); // } // System.out.println(set.toString()); List<Map<String,Object>> list = new ArrayList<>(); for (int i = 0; i < 10; i++) { Map<String,Object> map = new HashMap<>(); map.put("city","12,13,14,15"+i); map.put("phone","1885544288"+i); list.add(map); } Map<String,Object> map1 = new HashMap<>(); //放入空值 map1.put("city",""); map1.put("phone",""); list.add(map1); System.out.println(list.toString()); System.out.println("******************************************"); List<Object> city = list.stream().map(map -> (!"".equals(map.get("city")))?map.get("city"):"null").collect(Collectors.toList()); List<Object> phone = list.stream().map(map -> (!"".equals(map.get("phone")))?map.get("phone"):"null").collect(Collectors.toList()); System.out.println(city.toString()); System.out.println(phone.toString()); } }