@Test public void testToArray() throws Exception { assertArrayEquals(new Integer[]{1, 2, 3}, Stream.of(1, 2, 3).collect(toArray(Integer.class))); assertArrayEquals(new Integer[]{null}, Stream.of((Integer) null).collect(toArray(Integer.class))); assertArrayEquals(new Integer[]{}, Stream.<Integer>of().collect(toArray(Integer.class))); }
public static <T> Func1<Iterable<T>, T[]> toArray(final Class<T> cls) { return new Func1<Iterable<T>, T[]>() { @Override public T[] call(Iterable<T> value) { ArrayList<T> list = ToArrayList.<T>toArrayList().call(value); return list.toArray((T[]) Array.newInstance(cls, list.size())); } }; }
ToArray { public static <T> Func1<Iterable<T>, T[]> toArray(final Class<T> cls) { return new Func1<Iterable<T>, T[]>() { @Override public T[] call(Iterable<T> value) { ArrayList<T> list = ToArrayList.<T>toArrayList().call(value); return list.toArray((T[]) Array.newInstance(cls, list.size())); } }; } }
ToArray { public static <T> Func1<Iterable<T>, T[]> toArray(final Class<T> cls) { return new Func1<Iterable<T>, T[]>() { @Override public T[] call(Iterable<T> value) { ArrayList<T> list = ToArrayList.<T>toArrayList().call(value); return list.toArray((T[]) Array.newInstance(cls, list.size())); } }; }  }
ToArray { public static <T> Func1<Iterable<T>, T[]> toArray(final Class<T> cls) { return new Func1<Iterable<T>, T[]>() { @Override public T[] call(Iterable<T> value) { ArrayList<T> list = ToArrayList.<T>toArrayList().call(value); return list.toArray((T[]) Array.newInstance(cls, list.size())); } }; }  static Func1<Iterable<T>, T[]> toArray(final Class<T> cls); }
ToArray { public static <T> Func1<Iterable<T>, T[]> toArray(final Class<T> cls) { return new Func1<Iterable<T>, T[]>() { @Override public T[] call(Iterable<T> value) { ArrayList<T> list = ToArrayList.<T>toArrayList().call(value); return list.toArray((T[]) Array.newInstance(cls, list.size())); } }; }  static Func1<Iterable<T>, T[]> toArray(final Class<T> cls);  }