Here you can find the source of toCSVLine(String[] strArray)
public static String toCSVLine(String[] strArray)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; public class Main { public static String toCSVLine(String[] strArray) { if (strArray == null) { return ""; }// w w w . java 2 s. c om StringBuffer cvsLine = new StringBuffer(); for (int idx = 0; idx < strArray.length; idx++) { String item = addQuote(strArray[idx]); cvsLine.append(item); if (strArray.length - 1 != idx) { cvsLine.append(','); } } return cvsLine.toString(); } public String toCSVLine(ArrayList<String> strArrList) { if (strArrList == null) { return ""; } String[] strArray = new String[strArrList.size()]; for (int idx = 0; idx < strArrList.size(); idx++) { strArray[idx] = (String) strArrList.get(idx); } return toCSVLine(strArray); } private static String addQuote(String item) { if (item == null || item.length() == 0) { return "\"\""; } StringBuffer sb = new StringBuffer(); sb.append('"'); for (int idx = 0; idx < item.length(); idx++) { char ch = item.charAt(idx); if ('"' == ch) { sb.append("\"\""); } else { sb.append(ch); } } sb.append('"'); return sb.toString(); } }