1. public static boolean useList(String[] arr, String targetValue) { return Arrays.asList(arr).contains(targetValue);}
2. public static boolean useSet(String[] arr, String targetValue) {
Set<String> set = new HashSet<String>(Arrays.asList(arr)); return set.contains(targetValue);}
3. public static boolean useLoop(String[] arr, String targetValue) {
for (String s : arr) { if (s.equals(targetValue)) { return true; } } return false;}
4。下面的代码是错误。但是,为了这个回答的完整性,还是将其列在这里。binarySearch()方法仅能用于已排序的数组。不过,你将会被下面的结果所震惊。
public static boolean useArraysBinarySearch(String[] arr, String targetValue) { int a = Arrays.binarySearch(arr, targetValue); if (a > 0) { return true; } else { return false; }}
10K的数据
useList: 1678useSet: 25609useLoop: 1802useArrayBinary: 10未来星开发团队--狒狒QQ:9715234
继续阅读与本文标签相同的文章
上一篇 :
导入execl到数据库mysql
下一篇 :
java lambda 深入浅出
-
三分钟插入百万数据
2026-05-26栏目: 教程
-
DMA是什么意思
2026-05-26栏目: 教程
-
避免死锁的方法
2026-05-26栏目: 教程
-
java lambda 容易掉进的2个坑
2026-05-26栏目: 教程
-
myeclipse 配置堆内存
2026-05-26栏目: 教程
