Concats an element and an array.

@param firstElement the first element
@param array the array
@param <T> the type of the element in the array
@return a new array created adding the element in the second array after the first element
420845
public static <T> T[] concat(T firstElement, T... array) {
		@SuppressWarnings("unchecked")
		T[] result = (T[]) Array.newInstance( firstElement.getClass(), 1 + array.length );
		result[0] = firstElement;
		System.arraycopy( array, 0, result, 1, array.length );

		return result;
	}
573877
@SuppressWarnings({"rawtypes", "unchecked"})
    public static String join(final Object[] arrays, final String separator, final ElementConverter elementConverter) {

        if(arrays == null) {
            return "";
        }

        final int len = arrays.length;
        if(len == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for(int i=0; i < len; i++) {
            final Object element = arrays[i];
            sb.append(elementConverter.convertToString(element));

            if(separator != null && (i < len-1)) {
                sb.append(separator);
            }
        }

        return sb.toString();

    }
475823
public static <T> T[] concat(T[] first, T... second) {
		int firstLength = first.length;
		int secondLength = second.length;

		@SuppressWarnings("unchecked")
		T[] result = (T[]) Array.newInstance( first.getClass().getComponentType(), firstLength + secondLength );
		System.arraycopy( first, 0, result, 0, firstLength );
		System.arraycopy( second, 0, result, firstLength, secondLength );

		return result;
	}
586214
@SuppressWarnings("unchecked")
	public static <T> T[] insert(T[] buffer, int index, T... newElements) {
		return (T[]) insert((Object)buffer, index, newElements);
	}
1249732
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
        ArrayList<A> elements = new ArrayList<>();
        while (enumeration.hasMoreElements()) {
            elements.add(enumeration.nextElement());
        }
        return elements.toArray(array);
    }
625119
public static <E> E first(E[] array) {
        return new FirstElement<E>().apply(new ArrayIterator<>(array));
    }
665075
public static int[] Concatenate(int[] array, int[] array2) {
        int[] all = new int[array.length + array2.length];
        int idx = 0;

        //First array
        for (int i = 0; i < array.length; i++)
            all[idx++] = array[i];

        //Second array
        for (int i = 0; i < array2.length; i++)
            all[idx++] = array2[i];

        return all;
    }
998960
@SuppressWarnings("unchecked")
  public T[] pollToArray(T[] array) {
    int currentIndex = 0;
    LinkedElement<T> current = null;

    if (array.length == 0) {
      return array;
    }
    if (array.length > size) {
      array = (T[]) java.lang.reflect.Array.newInstance(array.getClass()
          .getComponentType(), size);
    }
    // do fast polling if the entire set needs to be fetched
    if (array.length == size) {
      for (int i = 0; i < entries.length; i++) {
        current = entries[i];
        while (current != null) {
          array[currentIndex++] = current.element;
          current = current.next;
        }
      }
      this.clear();
      return array;
    }

    boolean done = false;
    int currentBucketIndex = 0;

    while (!done) {
      current = entries[currentBucketIndex];
      while (current != null) {
        array[currentIndex++] = current.element;
        current = current.next;
        entries[currentBucketIndex] = current;
        size--;
        modification++;
        if (currentIndex == array.length) {
          done = true;
          break;
        }
      }
      currentBucketIndex++;
    }
    shrinkIfNecessary();
    return array;
  }
1162338
public static <E> Optional<E> maybeAt(long index, E[] array) {
        final Iterator<E> filtered = new FilteringIterator<E>(new ArrayIterator<E>(array), new AtIndex<E>(index));
        return new MaybeFirstElement<E>().apply(filtered);
    }
939766
@SafeVarargs
  /* #end */
  public final void addFirst(KType... elements) {
    ensureBufferSpace(elements.length);
    for (KType k : elements) {
      addFirst(k);
    }
  }
383786
public static long[] concatArrays(List<long[]> arrays, int start, int size) {
		long[] result = new long[size];

		// How many values we still need to move over
		int howManyLeft = size;

		// Where in the resulting array we're currently bulk-writing
		int targetPosition = 0;

		// Where we're copying *from*, in (one of) the source array.
		// Typically 0, except maybe for the first array in the list
		int from = start;

		for (int i = 0; i < arrays.size() && howManyLeft > 0; i++) {
			long[] current = arrays.get(i);

			// Can't copy more than the current source array size, or the grand total pointer
			int howManyThisRound = Math.min(current.length - from, howManyLeft);
			System.arraycopy(current, from, result, targetPosition, howManyThisRound);
			from = 0;
			howManyLeft -= howManyThisRound;
			targetPosition += howManyThisRound;
		}

		// If this is non-zero here, means we were asked to copy more than what we were provided
		if (howManyLeft > 0) {
			throw new ArrayIndexOutOfBoundsException(
					String.format("Not enough data, short of %d elements", howManyLeft));
		}
		return result;
	}
503419
public static String join(long[] array, CharSequence conjunction) {
		if (null == array) {
			return null;
		}

		final StringBuilder sb = new StringBuilder();
		boolean isFirst = true;
		for (long item : array) {
			if (isFirst) {
				isFirst = false;
			} else {
				sb.append(conjunction);
			}
			sb.append(item);
		}
		return sb.toString();
	}
850419
public static <T> T subArray(final T array, final int start, final int end) {

    if (isEmpty(array) || start < 0 || start > end || end >= Array.getLength(array)) {
      return array;
    }
    int newArraySize = end - start + 1;
    @SuppressWarnings("unchecked")
    T newArray = (T) buildArray(ClassUtils.getPrimitiveClass(ClassUtils.getComponentClass(array)),
      newArraySize, null);
    System.arraycopy(array, start, newArray, 0, newArraySize);
    return newArray;
  }
74193
public static String join ( CharSequence delimiter, CharSequence... elements ) {
        StringBuilder sb = new StringBuilder();
        for ( CharSequence element : elements ) {
            if ( sb.length() > 0 ) {
                if ( delimiter != null ) {
                    sb.append(delimiter);
                }
                else {
                    sb.append("null");
                }
            }
            sb.append(element);
        }
        return sb.toString();
    }
785937
public T removeFirst() {
		if (isEmpty()) {
			return null;
		}
		T firstElement = elements[firstIndex];
		elements[firstIndex] = null;
		firstIndex = incrementIndex(firstIndex, 0);
		return firstElement;
	}
1071322
public static <T> Level0ArrayOperator<String[],String> onArrayFor(final String... elements) {
        return onArrayOf(Types.STRING, VarArgsUtil.asRequiredObjectArray(elements));
    }
76876
public static <T> T getFirst(T array[]){
        return array!=null && array.length>0 ? array[0] : null;
    }