stream灵活应用,list和String互转

  1. 获取list对象中的指定字段
    List userId= scheduleStudents.stream().map(User::getUserId).collect(Collectors.toList());      List ids = list.stream().map(u-> u.getUserId()).collect(Collectors.toList());
  2. string转list
    List idList = Arrays.asList(componentRelate.getIds().split(","));
  3. string转list
    List idList = Arrays.asList(componentRelate.getIds().split(","))
            .stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
  4. 对象互转
    List finishCourse = finishCourseSchedules.stream().map(a->{ return getScheduleBase(a); }).collect(Collectors.toList());

你可能感兴趣的:(Java,java)