我正在研究一种方法,该方法将字符串数组作为输入并返回其首字母缩略词数组,这些首字母缩写词仅是大写字母。
例如:
[United Nations, United Federation of Planets, null, , ignore me] -> [UN, UFP, null, , ]
出于某种原因,我的代码没有返回任何内容,它还告诉我空检查是无效代码,我不知道为什么。
public static String[] convertStringsToAcronyms(String[] input)
{
int itemCount = input.length;
String[] result = new String[itemCount];
int k = 0;
for (String words : input) {
boolean checklowercase = words.toLowerCase().equals(words);
if (checklowercase || (words == ""))
result[k] = "";
if (words == null)
result[k] = null;
String add = "";
String[] ary = words.split("");
for (String letter : ary) {
char firstletter = letter.charAt(0);
if (Character.isUpperCase(firstletter))
add = add + firstletter;
}
result[k] = add;
k++;
add = "";
}
return result;
}