add item to the last of an array - Android java.lang

Android examples for java.lang:Array Element

Description

add item to the last of an array

Demo Code


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Main{
    /*from   w w w .  j a v a 2 s  . c  o m*/
    public static Integer[] addItem2Last(Integer[] datas, int item) {
        if (Validators.isEmpty(datas)) {
            return new Integer[] { item };
        }

        Integer[] ret = new Integer[datas.length + 1];

        for (int i = 0, length = datas.length; i < length; i++) {
            ret[i] = datas[i];
        }

        ret[datas.length] = item;
        return ret;
    }
}

Related Tutorials