convert list To String and use comma as separator - Android java.lang

Android examples for java.lang:String Join

Description

convert list To String and use comma as separator

Demo Code

import java.util.List;

public class Main{

    public static String listToString(List<String> list) {
        if (list == null)
            return null;
        StringBuilder result = new StringBuilder();
        boolean flag = false;
        while (list.iterator().hasNext()) {
            String string = list.iterator().next();
            if (!flag) {
                result.append(",");
            } else {
                flag = true;//from w  ww  .j a va  2  s  .  c o  m
            }
            result.append(string);
        }
        return result.toString();
    }

}

Related Tutorials