StringJoiner简化分隔字符带来的处理
import java.util.StringJoiner; public class StringJoinerDemo { public static void main(String[] args) { String[] names = {"A","B","C","D"}; StringJoiner stringJoiner = new StringJoiner(","); for (String name : names){ stringJoiner.add(name); } System.out.println(stringJoiner); } }
结果:A,B,C,D