将std :: max转换为Java [英] Convert std::max to Java

查看:137
本文介绍了将std :: max转换为Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C / C ++代码中的当前行:

I have the current line in C/C++ code:

double ma = *std::max_element(Dists[a], Dists[a] + size);

Dists [a] 数组大小 size

int Dists[size][size];

我在Java中寻找一个执行相同操作的等效函数。

I'm looking for an equivalent function in Java that would perform the same operation.

我不知道这个C / C ++函数是如何工作的,因为Dists [a] + size行。

I'm not sure how this C/C++ function is working because of the "Dists[a] + size" line.

推荐答案

假设您使用 Collections ,而不是实际的数组(建议):

Assuming you're using Collections, and not an actual array (which is recommended):

ArrayList<Integer> a; // initialized somewhere
...
Collections.max(a);

如果您使用实际的二维数组,请尝试:

If you're using an actual 2-dimensional array, try:

int[][] c; // initialized somewhere
int i; // set somewhere
List b = Arrays.asList(ArrayUtils.toObject(c[i]));
Collections.max(b);

比较元素使用自然排序

Elements are compared using their natural ordering.

这篇关于将std :: max转换为Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆