Search This Blog

Wednesday, March 29, 2017

Simple JAVA : How to convert a List to String

Use following sample code to quick convert List to String with concatenation, power of StringUtil (apache ;))

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class Test {

public static void main(String[] args) {

List a = new ArrayList();
a.add("tom");
a.add("jerry");
a.add("fun");
String s = StringUtils.join(a.toArray(),",");
System.out.println(s);

}

}

Out Put : tom,jerry,fun

Cheers,
Kapil

No comments:

Post a Comment

Thanks for your comment, will revert as soon as we read it.

Popular Posts