Java List to String toString(final List inMessages)

Here you can find the source of toString(final List inMessages)

Description

to String

License

Open Source License

Declaration

public static String toString(final List<String> inMessages) 

Method Source Code

//package com.java2s;
/*//w w  w. j  av a 2 s  . c o m
 * Copyright ? 2011-2014 EPAM Systems/B2BITS? (http://www.b2bits.com).
 *
 * This file is part of STAFF.
 *
 * STAFF is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * STAFF is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with STAFF. If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    public static String toString(final List<String> inMessages) {
        if (inMessages.isEmpty()) {
            return "No errors detected";
        }

        final StringBuilder builder = new StringBuilder();
        Integer index = 0;
        for (String msg : inMessages) {
            if (index == 0) {
                builder.append('\n');
            }
            builder.append(++index).append(") ").append(msg).append('\n');
        }
        return builder.toString();
    }
}

Related

  1. listToString(List list, String sep)
  2. listToString(String itemName, List list)
  3. toString(final List list)
  4. toString(final List list, final String separtor)
  5. toString(final List list)
  6. toString(final List input)
  7. toString(final List list, char delimiter)
  8. toString(final Object[] list)
  9. toString(List arguments)