Java Array Max Value maxValueInRemainingListElements(String[] numberList, int initialIndex)

Here you can find the source of maxValueInRemainingListElements(String[] numberList, int initialIndex)

Description

For an array of numbers, finds the max individual value from these numbers.

License

Open Source License

Parameter

Parameter Description
numberList The list of individual numbers
initialIndex The index of the first number to start checking onwards from

Return

The maximum number found in the list, from position of the initial index

Declaration

private static int maxValueInRemainingListElements(String[] numberList, int initialIndex) 

Method Source Code

//package com.java2s;
//file LICENSE in the root of the DomainHealth distribution.

public class Main {
    /**//w ww .j a va  2s .  c  o m
     * For an array of numbers, finds the max individual value from these 
     * numbers. For example if the input is "12,1,2,0,5" and initial index is
     * 3, will find the highest number from "0,5" which is "5". If there are
     * no numbers found, returns 0.
     * 
     * @param numberList The list of individual numbers
     * @param initialIndex The index of the first number to start checking onwards from
     * @return The maximum number found in the list, from position of the initial index 
     */
    private static int maxValueInRemainingListElements(String[] numberList, int initialIndex) {
        int maxVal = 0;
        int index = initialIndex;

        while (index < numberList.length) {
            if (numberList[index].length() > 0) {
                maxVal = Math.max(maxVal, Integer.parseInt(numberList[index]));
            }

            index += 1;
        }

        return maxVal;
    }
}

Related

  1. maxValue(double[] from)
  2. maxValue(final int[] arr)
  3. maxValue(float[] arr)
  4. maxValue(int[] arr)
  5. maxValue(int[] values)
  6. maxValuePos(final float[] in)
  7. maxY(final float[] vertices)