获取对象的最大值

时间:2015-09-07 09:05:13

标签: android arraylist

我有点问题。我从多个Beacon获取数据,然后将其放入arrayList中。现在我想要返回最近的那个。

{{1}}

1 个答案:

答案 0 :(得分:0)

Beacon nearest = null;
double distance = Double.MAX_VALUE;
for (Beacon beacon: arrayList){
  double maxDistance = beacon.getDistance();
  if (maxDistance < distance) {
    distance = maxDistance;
    nearest = beacon;
  }
}