Java: convertir List<String> pour une Chaîne de caractères

JavaScript a Array.join()

js>["Bill","Bob","Steve"].join(" and ")
Bill and Bob and Steve

Java ont quelque chose comme cela? Je sais que je peux bricoler quelque chose de moi-même avec StringBuilder:

static public String join(List<String> list, String conjunction)
{
   StringBuilder sb = new StringBuilder();
   boolean first = true;
   for (String item : list)
   {
      if (first)
         first = false;
      else
         sb.append(conjunction);
      sb.append(item);
   }
   return sb.toString();
}

...mais il n'y a aucun point en faisant cela, si quelque chose comme elle est déjà partie du JDK.

InformationsquelleAutor Jason S | 2009-11-17