Here you can find the source of join(String[] list, String separator)
Parameter | Description |
---|---|
list | The input list |
separator | The separator between two elements |
public static String join(String[] list, String separator)
//package com.java2s; /**/* www . j a v a 2s. c o m*/ * Copyright (c) 2009 University of Rochester * * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project * website http://www.extensiblecatalog.org/. * */ import java.util.Arrays; import java.util.List; public class Main { /** * Join the elements of an array of strings with a separator. * @param list The input list * @param separator The separator between two elements * @return The joined elements */ public static String join(String[] list, String separator) { return join(Arrays.asList(list), separator); } /** * Join the elements of a list with a separator. * @param list The input list * @param separator The separator between two elements * @return The joined elements */ public static String join(List list, String separator) { StringBuilder sb = new StringBuilder(); String sep = ""; for (Object member : list) { sb.append(sep).append(member.toString()); sep = separator; } return sb.toString(); } }