class StringList {
public LinkedList<String> constructList(String[] strs) {
LinkedList<String> ll = new LinkedList<String>();
HashSet<Integer> hs = new HashSet<Integer>();
for (int i = 0; i < strs.length; i++) {
if (hs.contains(strs[i].length())) {
continue;
} else {
ll.add(strs[i]);
hs.add(strs[i].length());
}
}
return ll;
}
public String search(LinkedList<String> list) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String result = "not exist";
for (String x : list) {
if (x.length() == n) {
return x;
}
}
return result;
}
}
6-4 根据要求,使用泛型和LinkedList编写StringList类,实现QQ号码查找的功能。 (30 分)java版
最新推荐文章于 2024-04-23 18:52:22 发布