使用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<string> set = new hashset<string>(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; }
更多java相关文章请关注java基础教程栏目。
以上就是java判断特定值是否在数组中的方法的详细内容。
