Java8 stream用法
// 测试stream List<Person> personList = new ArrayList<>(); Person p = null; for (int i = 0; i < 10; i++) { p = new Person(); p.setCode(String.valueOf(i)); p.setNameZh("路人:" + i); personList.add(p); } List<Person> personListFiltered = personList.stream().filter(person -> Integer.parseInt(person.getCode()) > 3).collect(Collectors.toList()); List<String> codeList = personList.stream().filter(person -> Integer.parseInt(person.getCode()) < 6).map(Person::getCode).collect(Collectors.toList()); Map<String,String> codeMap = personList.stream().filter(person -> Integer.parseInt(person.getCode()) < 6).collect(Collectors.toMap(Person::getCode,Person::getNameZh));