可以使用 Collectors.joining 方法将字符串数组转换为以冒号分隔的字符串,代码如下:

import java.util.Arrays;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        String[] arr = {'apple', 'banana', 'orange'};
        String result = Arrays.stream(arr)
                .collect(Collectors.joining(':'));
        System.out.println(result);
    }
}

输出结果为:

apple:banana:orange
Java 字符串数组转冒号分隔字符串:使用 JDK8 Stream 实现

原文地址: https://www.cveoy.top/t/topic/qwvD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录