About 211,000 results
Open links in new tab
  1. How do I initialize a byte array in Java? - Stack Overflow

    Jun 26, 2012 · In Java 6, there is a method doing exactly what you want: private static final byte[] CDRIVES = javax.xml.bind.DatatypeConverter.parseHexBinary ...

  2. java - What do we mean by Byte array? - Stack Overflow

    Oct 26, 2010 · A byte is 8 bits (binary data). A byte array is an array of bytes (tautology FTW!). You could use a byte array to store a collection of binary data, for example, the contents of a file. The downside to this is that the entire file contents must be loaded into memory.

  3. What is Java Byte Array and How should it be used?

    Jul 15, 2015 · If you do not know the difference between a byte and a common int (Integer), the main difference is the bit width: bytes are 8-bit and integers are 32-bit. You can read up on that here. If you do not know what an array is, an array is basically a sequence of items (in your case a sequence of bytes, declared as byte[]).

  4. Java Byte Array to String to Byte Array - Stack Overflow

    Its simple to convert byte array to string and string back to byte array in java. we need to know when to use 'new' in the right way. It can be done as follows: byte array to string conversion: byte[] bytes = initializeByteArray(); String str = new String(bytes); String to byte array conversion: String str = "Hello" byte[] bytes = str.getBytes();

  5. How to create an array of byte arrays in java - Stack Overflow

    In Java, an array where each element is itself an array is effectively just a 2D array, although Java doesn't require that each row have the same number of elements. In this particular case where you have a List<byte[]> and you wish to turn that into an array where each element of the array is itself a byte array you could use:

  6. Initialise and return a byte array in java - Stack Overflow

    Sep 19, 2012 · What you need to do is to return a new byte[] from the method like this: public byte[] methodThatAllocatesByteArray() { // create and populate array. return array; } and call it like this: byte[] temp = methodThatAllocatesByteArray(). Or you can initialise the array first, then pass the reference to that array to the other method like this:

  7. java - How to convert byte [] to Byte [] and the other way around ...

    Oct 17, 2012 · @Juvanis aha, I see that you use two "counters" in the for-loop: one to iterate over the primitive byte array and/or Byte object array, and another one for incrementing the index of the primitive byte array and/or Byte object array. To me, this is bad practice.

  8. java - How to assign a value to byte array - Stack Overflow

    Oct 3, 2011 · byte[] bytes = { (byte) 204, 29, (byte) 207, (byte) 217 }; Note the cast because Java bytes are signed - the cast here will basically force the overflow to a negative value, which is probably what you want. If you're actually trying to parse a string, you need to do that - split the string into parts and parse each one.

  9. how to compare the Java Byte [] array? - Stack Overflow

    Apr 1, 2014 · If you're trying to use the array as a generic HashMap key, that's not going to work. Consider creating a custom wrapper object that holds the array, and whose equals(...) and hashcode(...) method returns the results from the java.util.Arrays methods.

  10. Slicing byte arrays in Java - Stack Overflow

    Aug 21, 2013 · Creates a new byte buffer whose content is a shared subsequence of this buffer's content. So calling array() on that returned ByteBuffer returns the backing array in its entirety. To extract all the bytes from that view, you could do: byte[] bytes = new byte[slicedBuf.remaining()]; slicedBuf.read(bytes);