Lists { public static <E> List<E> concat(List<E> left, List<E> right) { int leftSize = left.size(); if (leftSize == 0) return right; int rightSize = right.size(); if (rightSize == 0) return left; E[] array = (E[]) new Object[leftSize + rightSize]; int i = 0; for (int l = 0; l < leftSize; l++) { array[i++] = left.get(l); } for (int r = 0; r < rightSize; r++) { array[i++] = right.get(r); } return Collections.unmodifiableList(Arrays.asList(array)); } Lists(); static List<E> ensureMutable(List<E> list); static List<E> ensureImmutable(List<E> list); static List<E> concat(List<E> left, List<E> right);  }
@Test public void concat_choosesNonEmpty() { List<Object> list = ImmutableList.of("foo"); assertThat(Lists.concat(list, Collections.emptyList())) .isSameAs(list); assertThat(Lists.concat(Collections.emptyList(), list)) .isSameAs(list); }
@Test public void concat_concatenates() { List<Object> list1 = ImmutableList.of("foo"); List<Object> list2 = ImmutableList.of("bar", "baz"); assertThat(Lists.concat(list1, list2)) .hasSameClassAs(Collections.unmodifiableList(list1)) .containsExactly("foo", "bar", "baz"); }