集册 Java实例教程 基于分隔符联接字符串数组

基于分隔符联接字符串数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

575
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
基于分隔符联接字符串数组
/*时 代 J a v a 公 众 号 - nowjava.com*/


//package com.book2s;


public class Main {

    public static void main(String[] argv) {

        String[] strings = new String[] { "1", "abc", "level", null,

                "book2s.com", "asdf 123" };

        System.out.println(join(strings));

    }


    /**

     * Joins a string array based on the delimiter

     * 

     * @param strings

     * @return

     */

    public static String join(String[] strings) {

        return join(strings, ",");

    }


    public static String join(String[] strings, String delim) {

        return join(strings, ",", false);

    }//NowJava.com - 时  代  Java 提供


    public static String join(String[] strings, String delim,

            boolean toUpper) {

        StringBuilder sb = new StringBuilder();

        boolean start = true;

        for (String string : strings) {

            if (start) {

              
展开阅读全文