stream

作者: DataSource | 来源:发表于2022-07-06 10:51 被阅读0次
     AiStudentStudyRecord record = aiStudentStudyRecords.stream().max(Comparator.comparingLong(AiStudentStudyRecord::getId)).get();
    
    public static void main(String[] args) {
    
           // 一个集合中放入4个学生对象
            List<Student> list = new ArrayList<>();
            list.add(new Student(10002L, "ZhangSan", 19, 175.2));
            list.add(new Student(10003L, "LiSi", 18, 180.1));
            list.add(new Student(10004L, "Peter", 19, 170.8));
            list.add(new Student(10001L, "KangKang", 18, 167.4));
            // 打印默认顺序
            System.out.println("默认顺序:");
            list.stream().forEach(System.out::println);
    
            // 按照id排序
            System.out.println("id升序:");
            list.stream().sorted(Comparator.comparing(Student::getId))
                    .forEach(System.out::println);
    
            // 按照id逆序排列
            System.out.println("id逆序:");
            list.stream().sorted(Comparator.comparing(Student::getId).reversed())
                    .forEach(System.out::println);
    
            // 按照年龄排序,再按照升高排序
            System.out.println("age和height排序:");
            list.stream().sorted(Comparator.comparing(Student::getAge).thenComparing(Student::getHeight))
                    .forEach(System.out::println);
    //
    //        System.out.println("ai_student_question_log".toUpperCase());
    ////        Map<Long, Integer> knowledgeProportionMap = new HashMap<>();
    ////        List<StudentKnowledgeMasteryDto> rows = new ArrayList<>();
    ////        Long a = 100L;
    ////        for (int i = 0; i < 10; i++) {
    ////            StudentKnowledgeMasteryDto build = StudentKnowledgeMasteryDto.builder().knowledgeId(a).mastery(i).build();
    ////            rows.add(build);
    ////        }
    ////        //List 转map
    ////        knowledgeProportionMap = rows.stream().collect(Collectors.toMap(StudentKnowledgeMasteryDto::getKnowledgeId, StudentKnowledgeMasteryDto::getMastery, (u, h) -> h));
    ////        System.out.println(knowledgeProportionMap);
    ////
    ////        //List 转map
    ////        Map<Long, StudentKnowledgeMasteryDto> map2 = new HashMap<>();
    ////        map2 = rows.stream().collect(Collectors.toMap(StudentKnowledgeMasteryDto::getKnowledgeId, Function.identity(), (u, h) -> h));
    ////        System.out.println(map2);
    ////
    ////        //map3
    ////        Map<Long, List<StudentKnowledgeMasteryDto>> map3 = new HashMap<>();
    ////        map3 = rows.stream().collect(Collectors.groupingBy(StudentKnowledgeMasteryDto::getKnowledgeId));
    ////        System.out.println(map3);
    ////
    ////
    ////        // List<Integer>
    ////        List<Integer> courseList = rows.stream().map(f -> f.getMastery()).collect(Collectors.toList());
    ////        System.out.println(courseList);
    
    
    
        public static void main(String[] args) {
            AtomicReference<Integer> lowRiskStudentNum = new AtomicReference<>(0);
            lowRiskStudentNum.updateAndGet(v -> v + 111);
            System.out.println(lowRiskStudentNum.get());
        }
    
    
    
    
    
        List<QuestionDetailDto> questionDetailChildrenCombList = aiPaperQuestionList.stream().filter(questionDetailDto ->
                        questionDetailDto.getParentId() != null
                                && questionDetailDto.getParentId() != 0 && questionDetailDto.getQuestionTypeId() != 6).collect(Collectors.toList());
    //
    //
    ////        nodeDtoList = nodeDtoList.stream().filter(dto -> dto.getPointType().equals(2)).collect(Collectors.toList());
    
    //        List<Long> teacherIds = aiClassesList.stream().map(AiClasses::getTeacherUserId).distinct().collect(Collectors.toList());
    
    
    //   Long[] longs = teachingPlanIdList.stream().toArray(Long[]::new);
    //
    //    }
    
    

    相关文章

      网友评论

          本文标题:stream

          本文链接:https://www.haomeiwen.com/subject/fvxybrtx.html