FileDocCategorySizeDatePackage
StringUtil.javaAPI DocExample720Sun Jun 03 22:43:18 BST 2001com.darwinsys.util

StringUtil

public class StringUtil extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringarrayToCommaList(java.lang.Object[] array)
Format an array of Object as a list with commas, like "apples, oranges, and bananas");

		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();
	
public static voidmain(java.lang.String[] args)

		String[] list = { "apples", "oranges", "pumpkins", "bananas" };
		System.out.println(arrayToCommaList(list));