Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:26:51+00:00 2026-06-09T19:26:51+00:00

What’s the easiest way add all of the elements in an array to a

  • 0

What’s the easiest way add all of the elements in an array to a list?

e.g.

List<Byte> l = new ArrayList<Byte>();
//Want to add each element in below array to l
byte[] b = "something".getBytes("UTF-8");

Is there some utility method or something that does this. I tried to use addAll, but that wants to add the actual array to the collection.

Thank you.

EDIT:

To clarify, I do want to do this with byte[] because I am going to eventually convert the list back to a byte[] and feed it into MessageDigest.update(). Does that help clarify?

EDIT 2:

So it seems like List<Byte> is bad; very bad. What data structure would be recommended if I am basically adding arrays of bytes (I am making a hash of some some SALTS and user information) to feed into MessageDigest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:26:53+00:00Added an answer on June 9, 2026 at 7:26 pm

    For byte[], you’re in trouble. Arrays.asList won’t work because you’ve got a byte[] rather than a Byte[].

    This is one of those “primitive vs class” problems. You can probably find 3rd party collection libraries which support this (such as the Apache Commons Lang project), but I don’t believe there’s anything out of the box. Alternatively, you could always just write the code yourself:

    List<Byte> l = new ArrayList<Byte>();
    for (byte b : "something".getBytes("UTF-8"))
    {
        l.add(b);
    }
    

    Note that this is a pretty horribly inefficient storage format for a sequence of bytes. Even though autoboxing will ensure you don’t create any extra Byte objects, you’re still going to have 4 or 8 bytes per element, as they’ll be references. It’s very rare for a List<Byte> to be appropriate – are you sure you need it here?

    If you’re actually dealing with classes, e.g. you’ve got a String[] and you want a List<String> then you can use Arrays.asList():

    String[] array = ...;
    List<String> list = Arrays.asList(array);
    

    That will return a read-only list wrapping the array though – if you want a mutable list, you can just pass that wrapper to the ArrayList constructor:

    String[] array = ...;
    List<String> list = new ArrayList<String>(Arrays.asList(array));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.