Java List to String toString(List strings)

Here you can find the source of toString(List strings)

Description

to String

License

Open Source License

Declaration

static String toString(List<String> strings) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008, 2010 VMware Inc.//from w  w  w. jav  a 2 s.  c o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   VMware Inc. - initial contribution
 *******************************************************************************/

import java.util.Iterator;
import java.util.List;

public class Main {
    static String toString(List<String> strings) {
        if (strings.isEmpty()) {
            return null;
        }

        StringBuilder builder = new StringBuilder();

        Iterator<String> iterator = strings.iterator();

        while (iterator.hasNext()) {
            builder.append(iterator.next());
            if (iterator.hasNext()) {
                builder.append(",");
            }
        }
        return builder.toString();
    }
}

Related

  1. toString(List input, String sep)
  2. toString(List list)
  3. toString(List list)
  4. toString(List list, String delimiter)
  5. toString(List list, String split)
  6. toString(List strings)
  7. toString(List list)
  8. toString(List list)
  9. toString(List list)