There are several ways to join strings in Java. Since Java 8, there's one way you probably don't know about: joining strings; that's what the StringJoiner class is for.
The StringJoiner class is often used to join lists of values or elements into a string, specifying a specific delimiter or prefix/suffix.
The code shown in the short creates a list of three strings ("Model", "My", "Mind") and initializes a StringJoiner named joiner with the delimiter "," and the appropriate prefix and suffix.
The forEach method of the stringList calls the add method of the joiner for each element in the list, which results in the elements being joined with the delimiter. The output is then Model, My, Mind in curly braces.
You can also represent joining in a short version. It might look like this.
This code creates a StringJoiner object with the delimiter ", ". Then, the string "Computer Science" is added to the StringJoiner, followed by "Programming" and "Software Engineering." The resulting string is: "Computer Science, Programming, Software Engineering."
На этой странице сайта вы можете посмотреть видео онлайн StringJoiner in Java | Learn Java programming | Concatenating strings длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь ModelMyMind 11 Февраль 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 1,236 раз и оно понравилось 43 зрителям. Приятного просмотра!