CollectionUtils { public static String join(final Collection<?> coll, String separate) { if (isEmpty(coll)) { return ""; } StringBuilder buf = new StringBuilder(); coll.stream().filter(a -> a != null).forEach(o -> { if (o instanceof Character) { buf.append(separate).append((Character) o); } else if (o instanceof String) { if (StringUtils.isNotBlank((String) o)) { buf.append(separate).append((String) o); } } else { buf.append(separate).append(o.toString()); } }); if (buf.length() < separate.length()) { return ""; } else { return buf.substring(separate.length()); } }  static boolean isEmpty(final Collection<?> coll); static boolean isNotEmpty(final Collection<?> coll); static String join(final Collection<?> coll, String separate);  }
@Test public void test_join_null() { String result = CollectionUtils.join(null, ","); Assertions.assertEquals("", result); }
@Test public void test_join_string() { List<String> list = new ArrayList<>(); list.add("aaa"); list.add(null); list.add("bbb"); String result = CollectionUtils.join(list, "=="); Assertions.assertEquals("aaa==bbb", result); }
@Test public void test_join_empty() { String result = CollectionUtils.join(List.of("", ""), "=="); Assertions.assertEquals("", result); }
@Test public void test_join_char() { String result = CollectionUtils.join(List.of(Character.valueOf('a'), Character.valueOf('b')), "-"); Assertions.assertEquals("a-b", result); }
@Test public void test_join_int() { List<Integer> list = new ArrayList<>(); list.add(123); list.add(null); list.add(456); String result = CollectionUtils.join(list, "-"); Assertions.assertEquals("123-456", result); }