Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static String toSqlInString(Collection col) { if (col == null) { return null; } return toSqlInString(col.toArray()); } public static String toSqlInString(Object[] col) { if (null == col) { return null; } int index = 0; StringBuilder buf = new StringBuilder(); Object value = null; while (index < col.length) { value = col[index]; if (value == null) { continue; } if (index != 0) { buf.append(","); } buf.append(addQuote(String.valueOf(value))); index++; } return buf.toString(); } public static String addQuote(String value) { StringBuilder str = new StringBuilder(); if (null == value) { return null; } str.append("\'").append(value).append("\'"); return str.toString(); } public static String toString(Object obj) { if (null == obj) { return ""; } return obj.toString(); } public static String toString(Object obj, String defaultStr) { if (null == obj) { return defaultStr; } return obj.toString(); } }