どうも、ちょげ(@chogetarou)です。
Map(マップ)のvalueの最小値を取得する方法を紹介します。
方法

Map(マップ)のvalueの最小値を取得するには、Collections.min()を使います。
まず、Collections.min()を呼び出します。
そして、Collections.min()の引数で、Mapからvalues()を呼び出します。
Integer maxValue = Collections.max(map.values());
上記のCollections.min()
は、valeus()を呼び出したMap(マップ)のvalueの最小値を取得します。
使用例
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Map<String, Integer> numbers = new HashMap<String, Integer>();
numbers.put("one", 1);
numbers.put("two", 2);
numbers.put("three", 3);
numbers.put("zero", 0);
numbers.put("four", 4);
numbers.put("five", 5);
Integer min = Collections.min(numbers.values());
System.out.println(min);
}
}
出力:
0
コメント