如何判断一个字符串是不是在数组中
展开全部
第一种方法:遍历数组
String[] arr1 = {"1","2","3","4","6","7"};
for (int i = 0; i < arr1.length; i++) {
if("5".equals(arr1[i])) {
System.out.println("包含");
}else {
System.out.println("不包含");
}
}
第二种方法:先把数组转换成list;再判断contains
String[] arr = {"1","2","3","4","6","7"};
List<String> list=Arrays.asList(arr);
System.out.println(list.contains("5"));
String[] arr1 = {"1","2","3","4","6","7"};
for (int i = 0; i < arr1.length; i++) {
if("5".equals(arr1[i])) {
System.out.println("包含");
}else {
System.out.println("不包含");
}
}
第二种方法:先把数组转换成list;再判断contains
String[] arr = {"1","2","3","4","6","7"};
List<String> list=Arrays.asList(arr);
System.out.println(list.contains("5"));
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询