Java Array to ArrayList byteArrayToArrayList(byte[] byteArray)

Here you can find the source of byteArrayToArrayList(byte[] byteArray)

Description

Converts the given array of bytes into a Java ArrayList

License

Open Source License

Parameter

Parameter Description
byteArray array of bytes to convert

Return

an ArrayList containing the given byteArray data

Declaration

public static ArrayList<Byte> byteArrayToArrayList(byte[] byteArray) 

Method Source Code

//package com.java2s;
/**/*from  www  . j  a  v a 2  s  .  co m*/
 * (C) 2011-2012 Alibaba Group Holding Limited.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 */

import java.util.ArrayList;

public class Main {
    /**
     * Converts the given array of bytes into a Java ArrayList
     *
     * @param byteArray
     *            array of bytes to convert
     * @return an ArrayList containing the given byteArray data
     */
    public static ArrayList<Byte> byteArrayToArrayList(byte[] byteArray) {
        return byteArrayToArrayList(byteArray, 0);
    }

    /**
     * Converts the given array of bytes into a Java ArrayList starting from the
     * given offset
     *
     * @param byteArray
     *            array of bytes to convert
     * @param offset
     *            where to start conversion from
     * @return an ArrayList containing the given byteArray data
     */
    public static ArrayList<Byte> byteArrayToArrayList(byte[] byteArray, int offset) {
        ArrayList<Byte> list = new ArrayList<Byte>(byteArray.length);
        for (int i = offset; i < byteArray.length; i++) {
            list.add(Byte.valueOf(byteArray[i]));
        }
        return list;
    }
}

Related

  1. arrayToArraylist(T[] array)
  2. asArrayList(Collection c)
  3. asArrayList(T... elements)
  4. asArrayList(T[] tArray)
  5. asArrayList(T[] values)
  6. byteArrayToShortArrayList(byte[] byteArray)
  7. toArrayList( Iterable iterable)
  8. toArrayList(Collection collection)
  9. toArrayList(Collection from)