Answers for "how to find shortest string in an array of string"

1

find shortest string in array java

public static String smallest(String words[]) {
    if (words == null || words.length < 1) {
        return "";
    }
    String smallest = words[0];
    for (int i = 1; i < words.length; i++) {
        if (words[i].length() < smallest.length()) {
            smallest = words[i];
        }
    }
    return smallest;
}// smallest
Posted by: Guest on July-08-2020

Code answers related to "how to find shortest string in an array of string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language