多个数组如何比对,求方法 我有8个数组,每个数组里的数据约1000条左右,现要找出这8个数组中相同元素个数大于等于2的所有结果,这该如何比对啊?求教! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接hash吧不过数据量这么小排序也不见得有多慢 import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public class Csdn { private static Set<Long> set = new HashSet<Long>(); private static List<Long> res = new ArrayList<Long>(); /** * @param args */ public static void main(String[] args) { long[] no1 = { 1, 2, 3, 4, 5 }; long[] no2 = { 2, 33, 44, 55, 66 }; long[] no3 = { 1, 432, 334, 44, 442 }; set(no1); set(no2); set(no3); print(); } private static void set(long[] nos) { for (int i = 0; i < nos.length; i++) { if (!set.add(nos[i])) { res.add(nos[i]); } } } private static void print() { for (Long l : res) { System.out.println(l); } }} spring配置文件中能否 ref到另一个包里的bean啊 求Castor官网,帮助文档之类 JTREE添加图片问题 求高手指点关于程序框架的使用问题 EJB3.0如何处理动态表 客户端通过wtc连接tuxedo时发生如下错误: Comparable中怎么可以直接CompType implements Comparable 来实现呢? 100分相送,关于Tomcat数据源的配置....我描述的很详尽,请大家看看....分数不够可再加。。 struts嵌套如何实现啊 先到先得 100分,谁有JBossOpenTool.jar 给俺一份! java 聊天|页面触发监听 高分讨论java的基础问题
不过数据量这么小
排序也不见得有多慢
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;public class Csdn { private static Set<Long> set = new HashSet<Long>(); private static List<Long> res = new ArrayList<Long>(); /**
* @param args
*/
public static void main(String[] args) { long[] no1 = { 1, 2, 3, 4, 5 };
long[] no2 = { 2, 33, 44, 55, 66 };
long[] no3 = { 1, 432, 334, 44, 442 }; set(no1);
set(no2);
set(no3);
print();
} private static void set(long[] nos) {
for (int i = 0; i < nos.length; i++) {
if (!set.add(nos[i])) {
res.add(nos[i]);
}
}
} private static void print() {
for (Long l : res) {
System.out.println(l);
}
}
}