In Java 1.8 gibt es einen neue schöne static join Methode, es braucht nur ein Begrenzer angegeben zu werden und schon wird ein schöner String zusammengebaut.
Hier mal ein kleines Beispiel:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void stringJoinTest() { | |
CharSequence delimiter = ","; | |
// Returns a new String composed of copies of the CharSequence elements | |
// joined together with a copy of the specified delimiter | |
String alleFarben = String.join(delimiter, "rot", "grün", "BLAU"); | |
assertEquals("rot,grün,BLAU", alleFarben); | |
} |
Was für neue schönen Methoden hast Du entdeckt?