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