find shortest string in array java

Solutions on MaxInterview for find shortest string in array java by the best coders in the world

showing results for - "find shortest string in array java"
Kristopher
04 Aug 2020
1public static String smallest(String words[]) {
2    if (words == null || words.length < 1) {
3        return "";
4    }
5    String smallest = words[0];
6    for (int i = 1; i < words.length; i++) {
7        if (words[i].length() < smallest.length()) {
8            smallest = words[i];
9        }
10    }
11    return smallest;
12}// smallest