Java Array Length Get lengthOfShortestIn(String[] strings)

Here you can find the source of lengthOfShortestIn(String[] strings)

Description

Return the length of the shortest string in the array.

License

BSD License

Parameter

Parameter Description
strings String[]

Return

int

Declaration

public static int lengthOfShortestIn(String[] strings) 

Method Source Code

//package com.java2s;
/**/*from   w w w .  j  a  v  a2  s . c om*/
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

public class Main {
    /**
     * Return the length of the shortest string in the array.
     * If any one of them is null then it returns 0.
     * 
     * @param strings String[]
     * @return int
     */
    public static int lengthOfShortestIn(String[] strings) {

        int minLength = Integer.MAX_VALUE;

        for (int i = 0; i < strings.length; i++) {
            if (strings[i] == null)
                return 0;
            minLength = Math.min(minLength, strings[i].length());
        }

        return minLength;
    }
}

Related

  1. lengthArray(Object[][] arr)
  2. lengthCheck(double[] src, double[] dest)
  3. lengthCheck(final byte[] buffer, final byte length)
  4. lengthNeeded(byte[] b)
  5. lengthOf(T[] array)
  6. lengthSQ(double[] vector)
  7. lengthToWrite(final byte[] data, final int offset, final int dataLength, final boolean rightTrim)
  8. lengthToZero(byte[] data, int offset)
  9. LengthVec3D(double[] vec)