Here you can find the source of printList(List
public static <T> void printList(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static <T> void printList(List<T> list) { if (list == null) { System.out.println("NULL"); return; }/* w ww.j a v a 2s . c o m*/ if (list.size() == 0) { System.out.println("[]"); return; } printNonEmptyList(list); } private static <T> void printNonEmptyList(List<T> list) { int len = list.size(); System.out.print("["); for (int i = 0; i < len; i++) { if (i == len - 1) { System.out.println(list.get(i) + "]"); } else { System.out.print(list.get(i) + ", "); } } } }