Java ArrayList Print prettyPrintArrayList(ArrayList input)

Here you can find the source of prettyPrintArrayList(ArrayList input)

Description

Makes an ArrayList of Strings pretty again!

License

Open Source License

Parameter

Parameter Description
input A List of Strings, e.G. List(1,2,3)

Return

A pretty pretty String, e.G. 1,2,3

Declaration

public static String prettyPrintArrayList(ArrayList<String> input) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Iterator;

public class Main {
    /**/*from  www  .  j  av a  2s .  c o  m*/
     * Makes an ArrayList of Strings pretty again!
     * 
     * @param input
     *            A List of Strings, e.G. List(1,2,3)
     * @return A pretty pretty String, e.G. 1,2,3
     */
    public static String prettyPrintArrayList(ArrayList<String> input) {
        StringBuilder sb = new StringBuilder();
        Iterator<String> i = input.iterator();

        while (i.hasNext()) {
            String next = i.next();
            sb.append(next);
            if (i.hasNext())
                sb.append(", ");
        }

        return sb.toString();
    }
}

Related

  1. print(ArrayList array)
  2. print(ArrayList tokens)
  3. print(ArrayList tokens)
  4. print(ArrayList l)