| Java List to String |
|
|
|
| Written by Charles | |||||
| Wednesday, 21 July 2010 22:36 | |||||
|
People often are keen to remove the square brackets that begin and end Java's implementation of List.toString, e.g. [ a, b, c ] so you can use the below not only to do that, but to choose your own prefix, suffix and delimiter. The code is HERE package net.proteanit.util; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Random; import java.util.List; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Description of the Class * * @author CEHJ * @created 10 March 2004 */ public class StringUtils { +--617 lines: public static final String HEXCHARS = "0123456789abcdef"; /** * * @param list The List to be represented as a String * @param header The String prepended to the String representation * @param separator The String separating each List element * @param footer The String appended to the String representation * * @return The String representation of the List */ public static String listToString(List<?extends Object> list, String header, String separator, String footer) { String delim = ""; StringBuilder sb = new StringBuilder(header); for (int i = 0; i < list.size(); i++) { sb.append(delim).append("" + list.get(i)); delim = separator; } return sb.append(footer).toString(); } +--139 lines: * }
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved." |
|||||
| Last Updated ( Wednesday, 21 July 2010 22:45 ) |



