Lists { @NonNull public static <T> List<T> appended(@NonNull List<T> list, @NonNull T t) { if (list.isEmpty()) { return Collections.singletonList(t); } else { final ArrayList<T> finalList = new ArrayList<>(list.size() + 1); finalList.addAll(list); finalList.add(t); return finalList; } } private  Lists(); @NonNull static List<T> merged(@NonNull List<T> list1, @NonNull List<T> list2); @NonNull static List<T> appended(@NonNull List<T> list, @NonNull T t);  }
@Test public void testAppended() throws Exception { final List<Integer> appendedList = Lists.appended(list, 4); assertThat(appendedList).isEqualTo(Arrays.asList(1, 2, 3, 4)); }