Here you can find the source of Max(ArrayList
Parameter | Description |
---|---|
values | Numeric values to test |
Parameter | Description |
---|---|
Exception | an exception |
public static double Max(ArrayList<Double> values) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.util.*; public class Main { /** Identifies the maximum numeric value in a list. */*from w w w .ja v a 2 s . c om*/ * @param values Numeric values to test * @return Maximum value * @throws Exception */ public static double Max(ArrayList<Double> values) throws Exception { ArrayList<Double> values2 = new ArrayList<Double>(); for (Double value : values) if (!value.equals(Double.NaN)) values2.add(value); if (values2.size() == 0) throw new Exception("The list was empty, so Max could not be determined."); int indexOfMax = 0; for (int i = 1; i < values2.size(); i++) { Double value = values2.get(i); if (value > values2.get(indexOfMax)) indexOfMax = i; } return values2.get(indexOfMax); } /** Adds the specified value to each element in the list. * @param list List of integer values * @param amountToAdd Amount to add to each element * return New list with modified values */ public static ArrayList<Integer> Add(ArrayList<Integer> list, int amountToAdd) { ArrayList<Integer> newList = new ArrayList<Integer>(); for (int i : list) newList.add(i + amountToAdd); return newList; } }