sdr 0.7

net.cscott.sdr.util
Class ListUtils

java.lang.Object
  extended by net.cscott.sdr.util.ListUtils

public final class ListUtils
extends Object

Convenience functions for lists and strings.


Method Summary
static String join(Collection<?> c, String insert)
          Return the string created by inserting insert between the members of c.
static String join(Collection<?> c, String insert, String preFinal)
          Return the string created by inserting insert between the members of c, and preFinal before the last one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

join

public static String join(Collection<?> c,
                          String insert)
Return the string created by inserting insert between the members of c.

Tests:
Note that non-string types are converted to Strings:
js> ListUtils.join(Tools.l(1), " + ")
1.0
js> ListUtils.join(Tools.l(1, 2), " + ")
1.0 + 2.0
js> ListUtils.join(Tools.l(1, 2, 3), " + ")
1.0 + 2.0 + 3.0

join

public static String join(Collection<?> c,
                          String insert,
                          String preFinal)
Return the string created by inserting insert between the members of c, and preFinal before the last one.

Tests:
js> ListUtils.join(Tools.l("apples"), ", ", " or ")
apples
js> ListUtils.join(Tools.l("apples", "oranges"), ", ", " or ")
apples or oranges
js> ListUtils.join(Tools.l("apples", "oranges", "pears"), ", ", " or ")
apples, oranges or pears
Non-string types are converted to strings:
js> ListUtils.join(Tools.l(1, 2, 3), " + ", " - ")
1.0 + 2.0 - 3.0

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian