【发布时间】:2017-01-06 15:01:02
【问题描述】:
我想有两个输出,因为如果我输入“ora”,我希望它输出两个字符串中的“orange”和“orange juice”,但你会怎么做?
class searcher {
ArrayList<String> toBecompared= new ArrayList<String>(Arrays.asList("orange", "orange juice", "apples", "cola", "soda"));
void search() {
String[] words = {text};
// text is a user input
// for loop test for if the "list" contains "text" (user input)
for (int i = 0; i < toBecompared.size(); i++) {
for (int w = 0; w < text.length(); w++) {
try {
if (toBecompared.get(i).contains(words[w])) {
println(words[w] +" " + toBecompared.get(i));
}
}
catch(Exception a) {
}
}
}
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow!您可以先使用tour,然后学习How to Ask 一个好问题并创建一个minimal reproducible example。这让我们更容易为您提供帮助。
标签: java arraylist output processing