Here you can find the source of toString(ArrayList a, String delim)
public static String toString(ArrayList a, String delim)
//package com.java2s; /* /* ww w . ja v a2 s. c o m*/ * Copyright 2016 Lutz Fischer <l.fischer@ed.ac.uk>. * * 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.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { public static String toString(Collection c, String delim) { if (c.isEmpty()) return ""; StringBuilder sb = new StringBuilder(); for (Object o : c) { sb.append(delim); sb.append(o.toString()); } return sb.substring(delim.length()); } public static String toString(int[] a, String delim) { if (a.length == 0) return ""; StringBuilder sb = new StringBuilder(Integer.toString(a[0])); for (int i = 1; i < a.length; i++) { sb.append(delim); sb.append(Integer.toString(a[i])); } return sb.toString(); } public static String toString(double[] a, String delim) { if (a.length == 0) return ""; StringBuilder sb = new StringBuilder(Double.toString(a[0])); for (int i = 1; i < a.length; i++) { sb.append(delim); sb.append(Double.toString(a[i])); } return sb.toString(); } public static String toString(long[] a, String delim) { if (a.length == 0) return ""; StringBuilder sb = new StringBuilder(Long.toString(a[0])); for (int i = 1; i < a.length; i++) { sb.append(delim); sb.append(Long.toString(a[i])); } return sb.toString(); } public static <T> String toString(T[] a, String delim) { if (a.length == 0) return ""; StringBuilder sb = new StringBuilder(a[0].toString()); for (int i = 1; i < a.length; i++) { sb.append(delim); sb.append(a[i].toString()); } return sb.toString(); } public static String toString(ArrayList a, String delim) { if (a.isEmpty()) return ""; StringBuilder sb = new StringBuilder(a.get(0).toString()); for (int i = 1; i < a.size(); i++) { sb.append(delim); sb.append(a.get(i).toString()); } return sb.toString(); } public static String toString(Iterable a, String delim) { return toString(a.iterator(), delim); } public static String toString(Iterator ai, String delim) { if (!ai.hasNext()) return ""; StringBuilder sb = new StringBuilder(ai.next().toString()); while (ai.hasNext()) { sb.append(delim); sb.append(ai.next().toString()); } return sb.toString(); } }