Java equivalent of PHP's implode(',' , array_filter( array () ))

前端 未结 9 1298
自闭症患者
自闭症患者 2020-12-29 19:32

I often use this piece of code in PHP

$ordine[\'address\'] = implode(\', \', array_filter(array($cliente[\'cap\'], $cliente[\'citta\'], $cliente[\'provincia\'         


        
9条回答
  •  猫巷女王i
    2020-12-29 20:03

    Using Streams (for Java 8 and later) would be an alternate possible solution for this.

    You are required to import

    java.util.stream.Collectors;
    

    to use the join process

    You may use:

    Arrays.asList("foo","bar").stream().collect(Collectors.joining(","));
    

    to achieve the desired result.

提交回复
热议问题