Check if an array exists in a HashSet<int[]>
问题 How do I check if an array exists in a HashSet ? For example: int[] a = new int[]{0, 0}; HashSet<int[]> set = new HashSet<>(); set.add(a); Then: int[] b = new int[]{0, 0}; set.contains(b); // ===> true 回答1: Using arrays int[] a = new int[] { 0, 0 }; HashSet<int[]> set = new HashSet<>(); set.add(a); int[] b = new int[] { 0, 0 }; boolean contains = set.stream().anyMatch(c -> Arrays.equals(c, b)); System.out.println("Contains? " + contains); Output: Contains? true It doesn’t exploit the fast