Changeset 1296 for trunk/java-utils/src/main/java/de/ugoe/cs/util
- Timestamp:
- 08/14/13 17:15:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-utils/src/main/java/de/ugoe/cs/util/ArrayTools.java
r927 r1296 96 96 return maxIndex; 97 97 } 98 99 /** 100 * <p> 101 * Finds the highest element in an array. If multiple elements have the 102 * maximum value, the index of the first one is returned; null-values are 103 * ignored. In case the parameter array is null, has length 0 or contains 104 * only null-values, -1 is returned. 105 * </p> 106 * 107 * @param array 108 * the array 109 * @return index of the element with the highest value, -1 in case of an 110 * invalid parameter 111 */ 112 public static <T> int findMax(double[] array) { 113 int maxIndex = -1; 114 double maxElement = Double.MIN_VALUE; 115 if (array != null) { 116 for (int i = 0; i < array.length; i++) { 117 if (array[i] > maxElement) { 118 maxElement = array[i]; 119 maxIndex = i; 120 } 121 } 122 } 123 return maxIndex; 124 } 98 125 99 126 /**
Note: See TracChangeset
for help on using the changeset viewer.