Here you can find the source of printLinkedList(String prefix, LinkedList> list)
public static String printLinkedList(String prefix, LinkedList<?> list)
//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(); } }