您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java判断特定值是否在数组中的方法

2024/8/5 4:16:36发布102次查看
java判断特定值是否在数组中的方法:
使用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判断特定值是否在数组中的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product