Java Array Resize prepend(String firstElement, String[] remaining)

Here you can find the source of prepend(String firstElement, String[] remaining)

Description

prepend

License

Open Source License

Declaration

public static String[] prepend(String firstElement, String[] remaining) 

Method Source Code

//package com.java2s;
/*/* w w w.j  a  v  a  2s .c  o m*/
 * Copyright (c) 2015-2017, Excelsior LLC.
 *
 *  This file is part of Excelsior JET API.
 *
 *  Excelsior JET API is free software:
 *  you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Excelsior JET API is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Excelsior JET API.
 *  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static String[] prepend(String firstElement, String[] remaining) {
        if (remaining == null) {
            return new String[] { firstElement };
        }
        ArrayList<String> res = new ArrayList<>();
        res.add(firstElement);
        res.addAll(Arrays.asList(remaining));
        return res.toArray(new String[remaining.length + 1]);
    }
}

Related

  1. arrayResize(double[] source, int targetSize)
  2. prepend(T element, T[] array)
  3. prependArg(String args[], String newArg)
  4. prependZeros(int n, byte[] message)
  5. resize2(double[][] array, int newsize1, int newsize2, double padding)