版权声明
1. 本站文章和资源均来自互联网收集和整理,本站不承担任何责任及版权问题。
2. 相关版权归作者及其公司所有,仅供学习研究用途,请勿用于商业目的。
3. 若侵犯您的版权,请发邮件至webmaster@ishare1.cn联系我们,我们确认后将立即删除。

一:使用List
public static boolean useList(String[] arr, String targetValue) {
return Arrays.asList(arr).contains(targetValue);
}
二:使用Set
public static boolean useSet(String[] arr, String targetValue) {
Set set = new HashSet(Arrays.asList(arr));
return set.contains(targetValue);
}
三:使用循环判断
public static boolean useLoop(String[] arr, String targetValue) {
for(String s: arr){
if(s.equals(targetValue))
return true;
}
return false;
}
四:使用Arrays.binarySearch()
Arrays.binarySearch()方法只能用于有序数组!!!如果数组无序的话得到的结果就会很奇怪。
查找有序数组中是否包含某个值的用法如下:
public static boolean useArraysBinarySearch(String[] arr, String targetValue) {
int a = Arrays.binarySearch(arr, targetValue);
if(a > 0)
return true;
else
return false;
}
推荐教程:java快速入门
if语句有四种使用形式: if(boolean类型表达式){…} if(条件){…}else{…} if(条件){…}else if(条件){…}else{…} if(条件){ if(条件){…} } else {…} 一:if(boolean类型表达式){……
爱分享




