判断数组中是否包含某个值

    xiaoxiao2026-03-26  12

    /** * @Description: 判断数组中是否包含某个值 * @author: GuXiYang * @date: 2015-9-25 下午2:32:50 * @param arr * @param targetValue * @see D瓜哥,http://www.diguage.com/ * @return */ public boolean useList(String[] arr, String targetValue) { return Arrays.asList(arr).contains(targetValue); } /** * Coder:D瓜哥,http://www.diguage.com/ */ public static boolean useSet(String[] arr, String targetValue) { Set<String> set = new HashSet<String>(Arrays.asList(arr)); return set.contains(targetValue); } /** * Coder:D瓜哥,http://www.diguage.com/ */ public static boolean useLoop(String[] arr, String targetValue) { for (String s : arr) { if (s.equals(targetValue)) { return true; } } return false; }
    转载请注明原文地址: https://ju.6miu.com/read-1308183.html
    最新回复(0)