Java Array Min Value minIndex(float[] arr)

Here you can find the source of minIndex(float[] arr)

Description

Returns the index to the smallest value in the array

License

Open Source License

Parameter

Parameter Description
arr array of floats

Return

the index

Declaration

public static int minIndex(float[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    /**// w ww . j  a  v  a  2 s  .c o  m
     * Returns the index to the smallest value in the array
     * 
     * @param arr array of floats
     * @return the index
     */
    public static int minIndex(float[] arr) {
        float min = Float.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
                index = i;
            }
        }

        return index;
    }

    /**
     * Returns the index to the smallest value in the array
     * 
     * @param dsqout array of ints
     * @return the index
     */
    public static int minIndex(int[] dsqout) {
        int min = Integer.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < dsqout.length; i++) {
            if (dsqout[i] < min) {
                min = dsqout[i];
                index = i;
            }
        }

        return index;
    }

    /**
     * Returns the index to the smallest value in the array
     * 
     * @param dsqout array of longs
     * @return the index
     */
    public static int minIndex(long[] dsqout) {
        long min = Long.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < dsqout.length; i++) {
            if (dsqout[i] < min) {
                min = dsqout[i];
                index = i;
            }
        }

        return index;
    }

    /**
     * Returns the index to the smallest value in the array
     * 
     * @param dsqout array of byte
     * @return the index
     */
    public static int minIndex(byte[] dsqout) {
        byte min = Byte.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < dsqout.length; i++) {
            if (dsqout[i] < min) {
                min = dsqout[i];
                index = i;
            }
        }

        return index;
    }

    /**
     * Returns the index to the smallest value in the array
     * 
     * @param dsqout array of short
     * @return the index
     */
    public static int minIndex(short[] dsqout) {
        short min = Short.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < dsqout.length; i++) {
            if (dsqout[i] < min) {
                min = dsqout[i];
                index = i;
            }
        }

        return index;
    }

    /**
     * Returns the index to the smallest value in the array
     * 
     * @param dsqout array of double
     * @return the index
     */
    public static int minIndex(double[] dsqout) {
        double min = Double.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < dsqout.length; i++) {
            if (dsqout[i] < min) {
                min = dsqout[i];
                index = i;
            }
        }

        return index;
    }
}

Related

  1. minIndex(double[] value)
  2. minIndex(double[] x, int length)
  3. minIndex(double[][] matrix, int column)
  4. minIndex(final double[] array)
  5. minIndex(final double[] values)
  6. minIndex(float[] vals)
  7. minIndex(float[] xs)
  8. minIndex(int[] array)
  9. minIndex(int[] from)