Java サンプル - List の最大値と最小値を検索
以下のサンプルは、Collections クラスの max() メソッドと min() メソッドを使用して List 内の最大値と最小値を取得する方法を示しています:
Main.java ファイル
import java.util.*;
public class Main {
public static void main(String[] args) {
List list = Arrays.asList("one Two three Four five six one three Four".split(" "));
System.out.println(list);
System.out.println("最大値:" + Collections.max(list));
System.out.println("最小値:" + Collections.min(list));
}
}
上記のコードを実行した出力結果は次のとおりです:
[one, Two, three, Four, five, six, one, three, Four] 最大值: three 最小值: Fourその他の拡張
Java サンプル