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推断特定值是不是在数组中的要领的细致内容,更多请关注ki4网别的相干文章!