📜  在数组java代码示例中找到最短的字符串

📅  最后修改于: 2022-03-11 14:52:24.056000             🧑  作者: Mango

代码示例1
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