Java Array to List toList(byte[] array)

Here you can find the source of toList(byte[] array)

Description

Turns the byte array into a Byte list.

License

Open Source License

Parameter

Parameter Description
array the array to convert

Return

the generated list

Declaration

public static List<Byte> toList(byte[] array) 

Method Source Code

//package com.java2s;
/*/*from   w  ww .jav a  2s . c om*/
 *   This program 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.
 *
 *   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Turns the byte array into a Byte list.
     * 
     * @param array   the array to convert
     * @return      the generated list
     */
    public static List<Byte> toList(byte[] array) {
        ArrayList<Byte> result;

        result = new ArrayList<>();
        for (byte element : array)
            result.add(element);

        return result;
    }

    /**
     * Turns the int array into an Integer list.
     * 
     * @param array   the array to convert
     * @return      the generated list
     */
    public static List<Integer> toList(int[] array) {
        ArrayList<Integer> result;

        result = new ArrayList<>();
        for (int element : array)
            result.add(element);

        return result;
    }

    /**
     * Turns the long array into a Long list.
     * 
     * @param array   the array to convert
     * @return      the generated list
     */
    public static List<Long> toList(long[] array) {
        ArrayList<Long> result;

        result = new ArrayList<>();
        for (long element : array)
            result.add(element);

        return result;
    }

    /**
     * Turns the double array into a Double list.
     * 
     * @param array   the array to convert
     * @return      the generated list
     */
    public static List<Double> toList(double[] array) {
        ArrayList<Double> result;

        result = new ArrayList<>();
        for (double element : array)
            result.add(element);

        return result;
    }

    /**
     * Turns the float array into a Float list.
     * 
     * @param array   the array to convert
     * @return      the generated list
     */
    public static List<Float> toList(float[] array) {
        ArrayList<Float> result;

        result = new ArrayList<>();
        for (float element : array)
            result.add(element);

        return result;
    }
}

Related

  1. toList(@SuppressWarnings("unchecked") T... ts)
  2. toList(boolean... booleans)
  3. toList(boolean[] array)
  4. toList(boolean[] array)
  5. toList(Boolean[] list)
  6. toList(byte[] array)
  7. toList(double[] array)
  8. toList(double[] array)
  9. toList(E... e)