Java中为List进行逗号连接

时间:2025-03-31 22:13:36
package ;

import ;
import ;
import ;

public class Main {
  public static void main(String[] args) {
    List<String> list = new ArrayList<>();
    ("0");
    ("1");
    ("2");
    ("3");
    ("4");
    ("5");
    ("6");
    ("7");
    ("8");
    ("9");

    ((",",list));
    (().collect((",")));
  }
}

效果:

0,1,2,3,4,5,6,7,8,9
0,1,2,3,4,5,6,7,8,9

关键点:

(",",list)
().collect((","))

参考

  • Convert a List to a Comma-Separated String in Java 8

相关文章