ImmutableIntSet implements IntSet { @Override public int[] toIntArray() { if (delegate instanceof IntSet) return ((IntSet)delegate).toIntArray(); else return U.toIntArray(delegate); } ImmutableIntSet(Set<Integer> delegate); static ImmutableIntSet wrap(Set<Integer> delegate); static ImmutableIntSet emptySet(); @Override boolean contains(int element); @Override boolean containsAll(Collection<?> coll); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @NotNull @Override Object[] toArray(); @NotNull @Override T[] toArray(@NotNull T[] a); @Override int[] toIntArray(); @Override String toString(); @NotNull @Override Iterator<Integer> iterator(); @Override boolean add(int element); @Override boolean remove(int element); @Override boolean add(Integer integer); @Override boolean remove(Object o); @Override boolean addAll(@NotNull Collection<? extends Integer> c); @Override boolean retainAll(@NotNull Collection<?> c); @Override boolean removeAll(@NotNull Collection<?> c); @Override void clear(); @Override void forEach(Consumer<? super Integer> act); @Override boolean removeIf(Predicate<? super Integer> filter); @Override Spliterator<Integer> spliterator(); @Override Stream<Integer> stream(); @Override Stream<Integer> parallelStream();  }
@Test public void toIntArray() { IntSet hashSet = ImmutableIntSet.wrap(new HashSet<>(Arrays.asList(2))); int[] fromHash = hashSet.toIntArray(); assertThat(fromHash.length, is(1)); assertThat(fromHash[0], is(2)); IntSet bitSet = ImmutableIntSet.wrap(new BitSetIntSet(2, Arrays.asList(2))); int[] fromBit = bitSet.toIntArray(); assertThat(fromBit.length, is(1)); assertThat(fromBit[0], is(2)); }