【发布时间】:2015-04-02 04:59:37
【问题描述】:
CandidateList 是一个包含候选人姓名的列表。 ballot 是一个字符串列表。我想检查选票名单上的名字是否与候选人名单上的任何名字相同。如果不是,那么我想检查选票上的下一个字符串,看看该字符串是否与候选列表中的任何名称相同。等等……
/**
* @param candidateList a list of candidate names
* @return the name of the first choice candidate for this Ballot from those
* in candidateList
*/
public String firstChoiceFrom(ArrayList<String> candidateList) {
String firstChoice = "";
String candidate = "";
for (int can = 0; can < candidateList.size(); can++) {
String bal = ballot.get(can); // gets next ballot
candidate = candidateList.get(can); // gets next candidate
while (!candidate.equals(bal))
{
}
//checks to see whether the first name on the ballot
if (candidate.equals(bal)) {
return candidate;
}
}
【问题讨论】:
-
你能有更好的格式,更清楚你真正想要什么吗?
-
我有代码,我只是觉得它的路要走。
-
@Name 我不认为没有人以此来评判你。我们是来帮忙的。我觉得如果你能有一个更好的语法并发布你对特定问题所做的事情,你会得到更好的结果
-
如果
Set满足您的要求并且您真的想要list1 ∩ list2,请查看docs.oracle.com/javase/7/docs/api/java/util/… -
我添加了我的代码。如果有人知道我能做什么,那将有所帮助。
标签: java