ObjectUtils { public static <T> String join( Collection<T> collection, String separator, Function<T, String> stringMapper ) { if ( collection == null ) { return null; } List<String> list = collection.stream().map( stringMapper ).collect( Collectors.toList() ); return StringUtils.join( list, separator ); }  @SafeVarargs static T firstNonNull( T... objects ); static boolean allNonNull( Object... objects ); static boolean anyIsTrue( Boolean... conditions ); static boolean anyIsFalse( Boolean... conditions ); static List<String> asStringList( Collection<?> objects ); static String join( Collection<T> collection, String separator, Function<T, String> stringMapper );  }
@Test public void testJoin() { DataElement deA = new DataElement( "DataElementA" ); DataElement deB = new DataElement( "DataElementB" ); DataElement deC = new DataElement( "DataElementC" ); List<DataElement> elements = Lists.newArrayList( deA, deB, deC ); String actual = ObjectUtils.join( elements, ", ", de -> de.getName() ); assertEquals( "DataElementA, DataElementB, DataElementC", actual ); assertEquals( null, ObjectUtils.join( null, ", ", null ) ); }