Java examples for java.util:Collection Join
Write code to merge Collection to String
import org.apache.log4j.Logger; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Collection; public class Main{ public static void main(String[] argv){ Collection strings = java.util.Arrays.asList("asdf","java2s.com"); System.out.println(merge(strings)); }/*from w w w . jav a2 s . c o m*/ public static String merge(final Collection<String> strings, final String separator) { final StringBuilder sb = new StringBuilder(); String localSeparator = ""; for (final String s : strings) { sb.append(localSeparator).append(s); localSeparator = separator; } return sb.toString(); } public static String merge(final Collection<String> strings) { return merge(strings, ""); } }