Here you can find the source of join(String[] strings, char delimiter)
Parameter | Description |
---|---|
strings | a parameter |
delimiter | a parameter |
public static String join(String[] strings, char delimiter)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**//from www . j a v a 2s .c om * Join string to a single string using the specified delimiter * * @param strings * @param delimiter * @return */ public static String join(String[] strings, char delimiter) { if (strings == null) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < strings.length; i++) { if (i > 0) { sb.append(delimiter); } if (strings[i] != null) { sb.append(strings[i]); } } return sb.toString(); } public static String join(List<String> strings, char delimiter) { if (strings == null) { return null; } StringBuilder sb = new StringBuilder(); int size = strings.size(); for (int i = 0; i < size; i++) { if (i > 0) { sb.append(delimiter); } String v = strings.get(i); if (v != null) { sb.append(v); } } return sb.toString(); } public static String toString(Object array, int off, int len, char delimiter, int maxArraySize) throws Throwable { if (array instanceof byte[]) { if (((byte[]) array).length > maxArraySize) { return ""; } return toString((byte[]) array, off, len, delimiter, true); } else if (array instanceof short[]) { if (((short[]) array).length > maxArraySize) { return ""; } return toString((short[]) array, off, len, delimiter, false); } else if (array instanceof int[]) { if (((int[]) array).length > maxArraySize) { return ""; } return toString((int[]) array, off, len, delimiter, false); } else if (array instanceof long[]) { if (((long[]) array).length > maxArraySize) { return ""; } return toString((long[]) array, off, len, delimiter, false); } else if (array instanceof float[]) { if (((float[]) array).length > maxArraySize) { return ""; } return toString((float[]) array, off, len, delimiter, false); } else if (array instanceof double[]) { if (((double[]) array).length > maxArraySize) { return ""; } return toString((double[]) array, off, len, delimiter, false); } else if (array instanceof Object[]) { if (((Object[]) array).length > maxArraySize) { return ""; } return toString((Object[]) array, off, len, delimiter); } else { throw new Exception("Object " + array + " is not an array."); } } public static String toString(byte[] b, int off, int len, char delimiter, boolean hex) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > b.length) { end = b.length; } for (int i = off; i < end; i++) { if (hex) { sb.append("0x"); sb.append(Integer.toHexString(b[i])); } else { sb.append(Integer.toString(b[i])); } if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } public static String toString(short[] sa, int off, int len, char delimiter, boolean hex) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > sa.length) { end = sa.length; } for (int i = off; i < end; i++) { if (hex) { sb.append("0x"); sb.append(Integer.toHexString(sa[i])); } else { sb.append(Integer.toString(sa[i])); } if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } public static String toString(int[] ia, int off, int len, char delimiter, boolean hex) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > ia.length) { end = ia.length; } for (int i = off; i < end; i++) { if (hex) { sb.append("0x"); sb.append(Long.toHexString(ia[i])); } else { sb.append(Long.toString(ia[i])); } if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } public static String toString(long[] la, int off, int len, char delimiter, boolean hex) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > la.length) { end = la.length; } for (int i = off; i < end; i++) { if (hex) { sb.append("0x"); sb.append(Long.toHexString(la[i])); } else { sb.append(Long.toString(la[i])); } if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } public static String toString(float[] fa, int off, int len, char delimiter, boolean hex) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > fa.length) { end = fa.length; } for (int i = off; i < end; i++) { if (hex) { sb.append("0x"); sb.append(Float.toHexString(fa[i])); } else { sb.append(Float.toString(fa[i])); } if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } public static String toString(double[] da, int off, int len, char delimiter, boolean hex) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > da.length) { end = da.length; } for (int i = off; i < end; i++) { if (hex) { sb.append("0x"); sb.append(Double.toHexString(da[i])); } else { sb.append(Double.toString(da[i])); } if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } public static String toString(Object[] oa, int off, int len, char delimiter) throws Throwable { StringBuilder sb = new StringBuilder(); int end = off + len; if (end > oa.length) { end = oa.length; } for (int i = off; i < end; i++) { sb.append(oa[i].toString()); if (i < end - 1) { sb.append(delimiter); } } return sb.toString(); } }