Add Element to Array - Android java.lang

Android examples for java.lang:array

Description

Add Element to Array

Demo Code


//package com.book2s;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static <T> T[] mergeArray(T t, T[] arrays) {
        List<T> newArrays = new ArrayList<T>();
        if (t != null) {
            newArrays.add(t);/*from w  w w  .  ja v  a  2s .  co m*/
        }
        if (arrays != null) {
            for (T e : arrays) {
                newArrays.add(e);
            }
        }
        return (T[]) newArrays.toArray();
    }
}

Related Tutorials