Answers for "return shortest string in array of stringz"

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 "return shortest string in array of stringz"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language