Here you can find the source of listToCsv(List> list)
Parameter | Description |
---|---|
list | a parameter |
public static String listToCsv(List<?> list)
//package com.java2s; /*//from www.ja va2 s. co m * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Iterator; import java.util.List; public class Main { /** * Converts a List of objects to a comma separated string of the objects' * string representations in the order given by the List's iterator. For * example: * * <blockquote> * * <pre> * List list = Arrays.toList(new String[] {"one", "two", "three"}; * System.out.println(listToCsv(list)); * </pre> * * </blockquote> would return the string "one,two,three". * * @param list * @return a List of objects to a comma separated string of the object's * string representations */ public static String listToCsv(List<?> list) { StringBuffer sb = new StringBuffer(); for (Iterator<?> iter = list.iterator(); iter.hasNext();) { sb.append(iter.next().toString()); if (iter.hasNext()) { sb.append(','); } } return sb.toString(); } }