@Test public void join_NullCollection_ReturnsNull() { assertThat(CollectionUtils.join(null, ","), isEmptyString()); }
public static String join(Collection<String> toJoin, String separator) { if (isNullOrEmpty(toJoin)) { return ""; } StringBuilder joinedString = new StringBuilder(); int currentIndex = 0; for (String s : toJoin) { if(s != null) { joinedString.append(s); } if (currentIndex++ != toJoin.size() - 1) { joinedString.append(separator); } } return joinedString.toString(); }
CollectionUtils { public static String join(Collection<String> toJoin, String separator) { if (isNullOrEmpty(toJoin)) { return ""; } StringBuilder joinedString = new StringBuilder(); int currentIndex = 0; for (String s : toJoin) { if(s != null) { joinedString.append(s); } if (currentIndex++ != toJoin.size() - 1) { joinedString.append(separator); } } return joinedString.toString(); } }
CollectionUtils { public static String join(Collection<String> toJoin, String separator) { if (isNullOrEmpty(toJoin)) { return ""; } StringBuilder joinedString = new StringBuilder(); int currentIndex = 0; for (String s : toJoin) { if(s != null) { joinedString.append(s); } if (currentIndex++ != toJoin.size() - 1) { joinedString.append(separator); } } return joinedString.toString(); }  }
CollectionUtils { public static String join(Collection<String> toJoin, String separator) { if (isNullOrEmpty(toJoin)) { return ""; } StringBuilder joinedString = new StringBuilder(); int currentIndex = 0; for (String s : toJoin) { if(s != null) { joinedString.append(s); } if (currentIndex++ != toJoin.size() - 1) { joinedString.append(separator); } } return joinedString.toString(); }  static boolean isNullOrEmpty(Collection<T> collection); static List<T> mergeLists(List<T> list1, List<T> list2); static String join(Collection<String> toJoin, String separator); }
CollectionUtils { public static String join(Collection<String> toJoin, String separator) { if (isNullOrEmpty(toJoin)) { return ""; } StringBuilder joinedString = new StringBuilder(); int currentIndex = 0; for (String s : toJoin) { if(s != null) { joinedString.append(s); } if (currentIndex++ != toJoin.size() - 1) { joinedString.append(separator); } } return joinedString.toString(); }  static boolean isNullOrEmpty(Collection<T> collection); static List<T> mergeLists(List<T> list1, List<T> list2); static String join(Collection<String> toJoin, String separator);  }