### Question:
StringUtils { public static Function<List<String>, String> joiningWithLastDelimiter( final String delimiter, final String lastDelimiter) { return list -> { final int last = list.size() - 1; if (last < 1) return String.join(delimiter, list); return String.join( lastDelimiter, String.join(delimiter, list.subList(0, last)), list.get(last)); }; }  static Function<List<String>, String> joiningWithLastDelimiter(
      final String delimiter, final String lastDelimiter);  }### Answer:
@Test public void joiningWithLastDelimiter() { Map<List<String>, String> testCases = new HashMap<>(); testCases.put(Arrays.asList("item1"), "item1"); testCases.put(Arrays.asList("item1", "item2"), "item1 and item2"); testCases.put(Arrays.asList("item1", "item2", "item3"), "item1, item2 and item3"); for (Map.Entry<List<String>, String> entry : testCases.entrySet()) { String joinedResult = entry.getKey().stream() .collect( Collectors.collectingAndThen( Collectors.toList(), StringUtils.joiningWithLastDelimiter(", ", " and "))); assertThat(joinedResult).isEqualTo(entry.getValue()); } }