Java Collection to Array toByteArray(Collection c)

Here you can find the source of toByteArray(Collection c)

Description

Converts a Collection of Bytes into a byte[] array.

License

Open Source License

Declaration

public static byte[] toByteArray(Collection<Byte> c) 

Method Source Code


//package com.java2s;
/*//from w w w.  ja v a2  s  .  c om
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc.
 *
 * 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,
 * version 2 of the License.
 *
 * 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 <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

import java.util.Collection;

public class Main {
    /** Converts a {@link Collection} of Bytes into a byte[] array. */
    public static byte[] toByteArray(Collection<Byte> c) {
        int pos = 0;
        byte byteArray[] = new byte[c.size()];
        for (Byte id : c)
            byteArray[pos++] = id;
        return byteArray;
    }
}

Related

  1. toArrayInt(Collection integerCollection)
  2. toArrays(Collection strings)
  3. toArrayString(Collection col, boolean spacing)
  4. toBaseTypedCollection(Collection initial)
  5. toByteArray(Collection c)
  6. toCharArray(Collection source)
  7. toCharArray(Collection patterns)
  8. toClassArray(Collection> collection)
  9. toClassArray(Collection> collection)