Non, pas dans la bibliothèque Java actuelle.
Dans JDK7, vous devriez être en mesure d'écrire String.join("", strings)
. Il a été constaté que "85%" des utilisations pour vouloir un index dans la boucle for chic était de faire une jointure de chaîne (que vous pouvez faire de toute façon).
Je suppose que si vous voulez être uber efficace, vous pourriez écrire quelque chose comme:
public static String concat(String... strs) {
int size = 0;
for (String str : strs) {
size += str.length;
}
final char[] cs = new char[size];
int off = 0;
try {
for (String str : strs) {
int len = str.length();
str.getChars(0, len, cs, off);
off += len;
}
} catch (ArrayIndexOutOfBoundsException exc) {
throw new ConcurrentModificationException(exc);
}
if (off != cs.length) {
throw new ConcurrentModificationException();
}
return new String(cs);
}
(Non compilé ou testé, bien sûr.)
En un an, lol :) –
IIRC, la dernière étape est maintenant due en Septembre (de 2010). –
Le jalon actuel M5 semble également parfaitement utilisable. – skaffman