【发布时间】:2012-09-19 20:02:15
【问题描述】:
我想做的是让一个数组将自己与另一个数组进行比较,如果它在比较数组中发现重复项,它将跳过以下语句,这是我目前得到的
for (int count=0; count < userId.length; count++) {
for (int integer=0; userId[count] != excluded[integer]; integer++) {
// The arrays hold either string or Long variables in them
// Continued code to finish off after checking array
}
}
我想要做的是让它工作,但可能但同时保持它尽可能简单。 如果代码实际上根本不清楚,我想比较两个数组 userId 和排除,我想要的是,如果数组中的任何 userId 值与排除中的任何匹配,那么就像数组状态一样,我想将它们排除在列表。
编辑:
运行时如果(excluded[counts].contains(user))
我得到了我想要的特定输出“很棒!”
但我现在遇到的问题是,如果我像 (!excluded[counts].contains(user))<br> 一样运行 if
我得到了排除的值,然后是一些重复的值减去那些显示的值
示例:
String[] userId = new String [] { "10", "15", "17", "20", "25", "33", "45", "55", "77" }
String[] excluded = new String[] { "15", 20", "55", "77" }
然后我进入我的循环来检查数组
int count=0;
for (String user : userId) {
for (int counts=0; counts < excluded.length; counts++) {
if (!excluded[counts].contains(user)) {
System.out.println("UID = " + userID[count]);
}
count++
!excluded 仍会显示我不想显示的 userId 实例,因此即使我希望它排除它,它仍会显示“UID = 15”,它确实如此,但只有一次看了 4 次,我看了 3 次。
【问题讨论】:
-
你是说你必须使用这个初始代码设置来解决你的问题,还是你愿意接受更好的方法的建议?
-
您的意思是:对于
userId中的每个元素,而不是excluded中的每个元素?