Java examples for java.util:Collection Join
Join Collection to String by comma
//package com.java2s; import java.util.Collection; public class Main { public static void main(String[] argv) { Collection c = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(toString(c)); }// ww w . j a v a2 s. c o m public static String toString(Collection<String> c) { StringBuilder sb = new StringBuilder(); for (String s : c) { sb.append(s).append(","); } if (sb.toString().endsWith(",")) { return sb.substring(0, sb.length() - 1); } else { return sb.toString(); } } }