Here you can find the source of join(Object[]... arrays)
Parameter | Description |
---|---|
arrays | a parameter |
public static Object[] join(Object[]... arrays)
//package com.java2s; import java.util.*; public class Main { /**/*from w w w . ja v a 2s .com*/ * @param arrays * @return the concatenation of the elements of the arrays into a new array, * ignoring arrays that are null (but including null entries in each * of the arrays) */ public static Object[] join(Object[]... arrays) { int size = totalSize(arrays); Object[] result = new Object[size]; int i = 0; for (Object[] array : arrays) { if (array != null) { for (int j = 0; j < array.length; ++j, ++i) { result[i] = array[j]; } } } return result; } public static <T> String join(Collection<T> things, String delim) { StringBuilder sb = new StringBuilder(); boolean first = true; for (T t : things) { if (first) { first = false; } else { sb.append(delim); } sb.append(t); } return sb.toString(); } /** * @param arrays * @return the sum of the lengths of the arrays, ignoring arrays that are * null (but counting null entries) */ public static int totalSize(Object[]... arrays) { if (arrays == null) { return 0; } int size = 0; for (Object[] array : arrays) { size += (array == null ? 0 : array.length); } return size; } public static String toString(Object[] arr) { return toString(arr, true); } public static String toString(Object[] arr, boolean square) { if (arr == null) { return "null"; } StringBuffer sb = new StringBuffer(); if (square) { sb.append("["); } else { sb.append("("); } for (int i = 0; i < arr.length; ++i) {// Object o : arr ) { if (i > 0) { sb.append(","); } if (arr[i] == null) { sb.append("null"); } else { sb.append(arr[i].toString()); } } if (square) { sb.append("]"); } else { sb.append(")"); } return sb.toString(); } }