java - java 二维数组列表的最大值

标签 java arraylist max

我有:

ArrayList<List<Integer>> group = new ArrayList<List<Integer>>();
group.add(Arrays.asList(1, 2, 3));
group.add(Arrays.asList(4, 5, 6));
group.add(Arrays.asList(7, 8, 9));

如何找到第一、第二、第三列和第一、第二、第三行的最大值?

这是我尝试过的:

int aMaxR1, aMaxR2, aMaxR3;
int aMinC1, aMinC2, aMinC3;

aMaxR1 = Collections.min(group.get(here could be first row));
aMaxR2 = Collections.min(group.get(here could be second row));
aMaxR3 = Collections.min(group.get(here could be third row));

aMaxC1 = Collections.max(group.get(here could be first column));
aMaxC2 = Collections.max(group.get(here could be second column));
aMaxC3 = Collections.max(group.get(here could be third column));

最佳答案

要获得行中的最大值,这非常简单,而且您的方法是正确的。

aMaxR1 = Collections.max(group.get(0));

对于列,您可以执行 for 循环:

 for(int i = 0; i < group.size(); i++){
     System.out.println(Math.max(Math.max(group.get(0).get(i), group.get(1).get(i)), group.get(2).get(i)));
  }

输出:

7
8
9

关于java - java 二维数组列表的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19882950/

相关文章:

MYSQL - 选择每个玩家每天的最高分数

javascript - 使用jquery查找属性中的最小值和最大值

max - NSTextField 设置最大字符数

java - Servlet 不使用 PrintWriter 对象打印任何内容

java - 无法使用 .getAllHeaders() 方法获取所有电子邮件 header

java - Spring 不能正常工作但没有错误信息

java - 将数组列表转换为 html 表

java - Spring 启动和 ddl-auto 问题

java - 将ArrayList中的对象转换为String

java - 如何根据键值将 2 个 ArrayList<HashMap<String, String>> 合并为 1 个?