Lists { @SuppressWarnings("unchecked") public static <X> X[] toArray(List<X> inputs, Class<X> klazz) { if (null == inputs) { return (X[]) Array.newInstance(klazz, 0); } X[] out = inputs.toArray((X[]) Array.newInstance(klazz, inputs.size())); return out; } private  Lists(); static Y foldLeft(Y initial, List<X> inputList, Aggregator<? super X, Y> op); static Y foldRight(Y initial, List<X> inputList, Aggregator<? super X, Y> op); static List<Y> map(List<X> inputs, Func<? super X, ? extends Y> mapper); @SuppressWarnings("unchecked") static X[] toArray(List<X> inputs, Class<X> klazz); static List<X> distinct(List<X> inputs);  }
@Test public void testToArray() { String[] oneString = Lists.toArray(Collections.singletonList("foo"), String.class); assertEquals(1, oneString.length); assertEquals("foo", oneString[0]); oneString = Lists.toArray(Collections.<String>singletonList(null), String.class); assertEquals(1, oneString.length); assertNull(oneString[0]); String[] emptyOut = Lists.toArray(Collections.<String>emptyList(), String.class); assertNotNull(emptyOut); assertEquals(0, emptyOut.length); String[] nulOut = Lists.<String>toArray(null, String.class); assertNotNull(nulOut); assertEquals(0, nulOut.length); }