Java List Print printLinkedList(String prefix, LinkedList list)

Here you can find the source of printLinkedList(String prefix, LinkedList list)

Description

print Linked List

License

Open Source License

Declaration

public static String printLinkedList(String prefix, LinkedList<?> list) 

Method Source Code

//package com.java2s;
/*//from   w ww.j  a  v a  2  s  .  com
 * Copyright (C) 2014-2015 Jos? Luis Risco Mart?n <jlrisco@ucm.es> and 
 * Saurabh Mittal <smittal@duniptech.com>.
 *
 * This library 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.
 *
 * This library 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 this library; if not, see
 * http://www.gnu.org/licenses/
 *
 * Contributors:
 *  - Jos? Luis Risco Mart?n <jlrisco@ucm.es>
 *  - Saurabh Mittal <smittal@duniptech.com>
 */

import java.util.Iterator;
import java.util.LinkedList;

public class Main {
    public static String printLinkedList(String prefix, LinkedList<?> list) {
        StringBuilder sb = new StringBuilder();
        Iterator<?> it = list.iterator();
        sb.append(prefix).append(" [");
        while (it.hasNext()) {
            sb.append(it.next().toString());
        }
        sb.append("]");
        return sb.toString();
    }
}

Related

  1. printIndex(final Map> index)
  2. printIntegerArrayList(ArrayList arr)
  3. printIntegerList(List array)
  4. printItemList(String label, List itemList)
  5. printLines(List lines)
  6. printList(Collection list)
  7. printList(final List list)
  8. printList(List l)
  9. printList(List l)