Here you can find the source of commaSeparatedList(Object... values)
Parameter | Description |
---|---|
values | array of objects |
public static String commaSeparatedList(Object... values)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**//ww w. j av a 2 s . c om * creates a comma separated list out of objects in strings * * @param values array of objects * @return comma separated list */ public static String commaSeparatedList(Object... values) { String toAdd = ""; for (int i = 0; i < values.length; i++) { if (i == values.length - 1) { toAdd += stringify(values[i]); } else { toAdd += stringify(values[i]) + ", "; } } return toAdd; } /** * creates a comma separated list out of objects in string * * @param values list of objects * @return comma separated list */ public static String commaSeparatedList(List<Object> values) { return commaSeparatedList(values.toArray(new Object[values.size()])); } /** * Converts a object into a string * * @param value object to convert * @return String value of object */ public static String stringify(Object value) { if (value == null) { return ""; } else if (value instanceof Boolean) { boolean b = (Boolean) value; return (b) ? "true" : "false"; } else { if (value instanceof Integer) { return "" + value; } else if (value instanceof Double) { return "" + value; } else if (value instanceof Long) { return "" + value; } else if (value instanceof Float) { return "" + value; } else if (value instanceof Enum) { return value.toString().toLowerCase(); } else { return value.toString(); } } } }