Java List to String asString(List list)

Here you can find the source of asString(List list)

Description

as String

License

Open Source License

Declaration

public static String asString(List list) 

Method Source Code

//package com.java2s;
/**/*  ww w .j a v a2  s  .co  m*/
 * $Revision $
 * $Date $
 *
 * Copyright (C) 2005-2010 Jive Software. All rights reserved.
 *
 * Licensed 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 {
    public static String asString(List list) {
        if (list == null || list.isEmpty())
            return "";
        StringBuilder builder = new StringBuilder();
        for (Iterator i$ = list.iterator(); i$.hasNext(); builder.append(",")) {
            long a = ((Long) i$.next()).longValue();
            builder.append(a);
        }

        if (builder.charAt(builder.length() - 1) == ',')
            builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }
}

Related

  1. asString(List commandLine)
  2. asStringList( Collection objects)
  3. asStringList(Collection list)
  4. asStringList(Collection objects)