Studying Java 8 (String Joiner and join)

sample

import java.util.StringJoiner;

/**
 *Studying String join method and String Joiner
 * @author komikcomik
 *
 */
public class JoinTest {

	public static void main(String[] args) {

		String[] strs = {"a","b","c"};
		String joinStr = String.join(",", strs);
		System.out.println(joinStr);

		StringJoiner sj = new StringJoiner(",");
		joinStr = sj.add("X").add("Y").add("Z").toString();
		System.out.println(joinStr);
	}

}

result

a,b,c
X,Y,Z

It may be useful if you want to format it into a standard format.

Recommended Posts

Studying Java 8 (String Joiner and join)
[Java] String comparison and && and ||
[Java] About String and StringBuilder
Studying Java ―― 3
Studying Java ―― 9
Java string
Studying Java ―― 4
Studying Java -5
Studying Java ―― 1
Studying Java # 0
Studying Java ―― 8
Studying Java 8 (StaticIF and Default methods)
Studying Java ―― 7
Studying Java ―― 2
Studying Java ①
Studying java9 (dropWhile, takeWhile and Stream.ofNullable)
Studying Java -10
[Java] String padding
Studying Java 8 (Optional)
Java string processing
XXE and Java
Studying Java 8 (Stream)
Split string (Java)
[Java] The confusing part of String and StringBuilder
<java> Read Zip file and convert directly to string
Getters and setters (Java)
Studying Java 8 (Collector / Collectors)
[Java] Thread and Runnable
String and stringbuffer and string builder
Java true and false
[Java] String join execution speed comparison (+ operator vs StringBuilder)
Java string multiple replacement
Studying Java 8 (see method)
[Note] Java: String search
Studying Java 8 (see constructor)
[Note] Java: String survey
[Java] About Objects.equals () and Review of String comparisons (== and equals)
About Java String class
Java --Serialization and Deserialization
[Java] Arguments and parameters
Studying Java ~ Part 8 ~ Cast
timedatectl and Java TimeZone
[Java] Branch and repeat
Studying Java 8 (lambda expression)
[Java] Variables and types
java (classes and instances)
[Java] Handling of character strings (String class and StringBuilder class)
[Java] Overload and override
Memorandum No.4 "Get a character string and decorate it" [Java]
Study Java # 2 (\ mark and operator)
[Java] Difference between == and equals
[Java] Stack area and static area
Java inflexible String class substring
[Java] Generics classes and generics methods
Java encryption and decryption PDF
Java and Iterator Part 1 External Iterator
Java if and switch statements
Apache Hadoop and Java 9 (Part 1)
String concatenation and line breaks
[Java] HashCode and equals overrides
☾ Java / Iterative statement and iterative control statement