有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在java中查找特定数字范围的列表

这是我的代码,让学生得到70分及以上的分数

public static List<List<String>> higher (List<List<String>> data, String high) {
    
  return data.stream()    
             .filter(e-> e.get(6).equalsIgnoreCase(high))
             .collect(Collectors.toList());
}

这是我的结果

[70]

我能知道如何让所有70岁及以上的学生


共 (2) 个答案

  1. # 1 楼答案

    像这样试试。需要将字符串转换为int进行比较。最好将高点作为int来传递

    public static List<List<String>> Distinction(List<List<String>> data, int high) {
          
          return data.stream()    
                     .filter(e-> Integer.parseInt(e.get(2)) >= high)
                     .collect(Collectors.toList());
    }
    
  2. # 2 楼答案

    测试这个:

    public static List<List<String>> distinction(List<List<String>> data, Integer high) {
    
            return data.stream()
                    .filter(e-> Integer.parseInt(e.get(6)) >= high)
                    .collect(Collectors.toList());
    }
    

    高应该是70