Java List Join join(List parts)

Here you can find the source of join(List parts)

Description

join

License

Apache License

Declaration

public static String join(List<?> parts) 

Method Source Code


//package com.java2s;
/*// w ww .j a va  2s . c o  m
 * This file is part of the PSL software.
 * Copyright 2011-2015 University of Maryland
 * Copyright 2013-2017 The Regents of the University of California
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.List;

public class Main {
    public static final char DEFAULT_DELIM = ',';

    public static String join(List<?> parts) {
        return join(parts, DEFAULT_DELIM);
    }

    public static String join(List<?> parts, char delim) {
        return join(parts, "" + delim);
    }

    public static String join(List<?> parts, String delim) {
        StringBuilder builder = new StringBuilder(parts.size() * 2 - 1);

        for (int i = 0; i < parts.size(); i++) {
            builder.append(parts.get(i));

            if (i != parts.size() - 1) {
                builder.append(delim);
            }
        }

        return builder.toString();
    }

    public static String join(Object[] parts) {
        return join(parts, DEFAULT_DELIM);
    }

    public static String join(Object[] parts, char delim) {
        return join(parts, "" + delim);
    }

    public static String join(Object[] parts, String delim) {
        StringBuilder builder = new StringBuilder(parts.length * 2 - 1);

        for (int i = 0; i < parts.length; i++) {
            builder.append(parts[i]);

            if (i != parts.length - 1) {
                builder.append(delim);
            }
        }

        return builder.toString();
    }

    public static String join(int[] parts) {
        return join(parts, DEFAULT_DELIM);
    }

    public static String join(int[] parts, char delim) {
        return join(parts, "" + delim);
    }

    public static String join(int[] parts, String delim) {
        StringBuilder builder = new StringBuilder(parts.length * 2 - 1);

        for (int i = 0; i < parts.length; i++) {
            builder.append(parts[i]);

            if (i != parts.length - 1) {
                builder.append(delim);
            }
        }

        return builder.toString();
    }

    public static String join(double[] parts) {
        return join(parts, DEFAULT_DELIM);
    }

    public static String join(double[] parts, char delim) {
        return join(parts, "" + delim);
    }

    public static String join(double[] parts, String delim) {
        StringBuilder builder = new StringBuilder(parts.length * 2 - 1);

        for (int i = 0; i < parts.length; i++) {
            builder.append(parts[i]);

            if (i != parts.length - 1) {
                builder.append(delim);
            }
        }

        return builder.toString();
    }
}

Related

  1. join(List items, String delimiter)
  2. join(List list)
  3. join(List list, String delim)
  4. join(List list, String sep)
  5. join(List objects, String delimiter)
  6. join(List resultList, String sep)
  7. join(List strings, String delimiter)
  8. join(List list1, List list2)
  9. join(List array, char c)