第一种方法:遍历数组
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"));
新闻热点
疑难解答