Here you can find the source of arrayToCommaList(Object[] array)
Parameter | Description |
---|---|
array | The objects to be stringified |
public static String arrayToCommaList(Object[] array)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w.ja v a 2 s.c o m*/ * Format an array of Object as a list with commas, * like "apples, oranges, and bananas"); * XXX Should have a boolean for the final comma :-) * * @param array The objects to be stringified * @return a pretty list */ public static String arrayToCommaList(Object[] array) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; i++) { if (i > 0 && i < array.length - 1) { sb.append(','); } if (i > 0) { sb.append(' '); } if (i == (array.length - 1)) { sb.append("and "); } sb.append(array[i]); } return sb.toString(); } }