Here you can find the source of listToString(List
public static String listToString(List<Double> list)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.List; public class Main { protected static final NumberFormat formatter = new DecimalFormat("###.###"); public static String listToString(List<Double> list) { if (list.isEmpty()) { return "[]"; }//from ww w.j ava 2s . c om StringBuilder str = new StringBuilder(); str.append("[").append(formatDouble(list.get(0))); for (int i = 1; i < list.size(); i++) { str.append(", ").append(formatDouble(list.get(i))); } str.append("]"); return str.toString(); } public static String formatDouble(double value) { return formatter.format(value); } public static String formatDouble(double value, int n) { StringBuilder str = new StringBuilder("###."); for (int nn = 0; nn < n; nn++) { str.append("#"); } NumberFormat newFormatter = new DecimalFormat(str.toString()); return newFormatter.format(value); } }