1 package org.robolectric.util; 2 3 import java.util.Collection; 4 5 /** 6 * Utility class used to join strings together with a delimiter. 7 */ 8 public class Join { join(String delimiter, Collection collection)9 public static String join(String delimiter, Collection collection) { 10 String del = ""; 11 StringBuilder sb = new StringBuilder(); 12 for (Object obj : collection) { 13 String asString = obj == null ? null : obj.toString(); 14 if (obj != null && asString.length() > 0) { 15 sb.append(del).append(obj); 16 del = delimiter; 17 } 18 } 19 return sb.toString(); 20 } 21 join(String delimiter, Object... collection)22 public static String join(String delimiter, Object... collection) { 23 String del = ""; 24 StringBuilder sb = new StringBuilder(); 25 for (Object obj : collection) { 26 String asString = obj == null ? null : obj.toString(); 27 if (asString != null && asString.length() > 0) { 28 sb.append(del).append(asString); 29 del = delimiter; 30 } 31 } 32 return sb.toString(); 33 } 34 } 35