我有以下的数组列表比较两个数组列表
List<Long> ids = new ArrayList<Long>();
List<Long> empIds = new ArrayList<Long>();
现在我需要比较这2个阵列和检查,如果在IDS的任何值有在empIds。如果是,我需要用布尔值true来退出。我通过以下方式完成了这项工作。
for (Long id : ids) {
if (empIds.contains(id)) {
checker = true;
break;
}
}
但这需要很多时间。任何人都可以帮我优化这个吗?
数组的大小是多少?并请分享一些时间输出。 我不认为有一个更简单的方法 –
ids或empIds排序或几乎排序? –