471,825 Members | 1,272 Online

# How convert from vector to Byte array

Hi,
How to convert a Vector to a Byte array....i have vector which contains a Byte array.....i need to convert the vector into Byte array...

--------------------------------------------------------------------------------
Aug 25 '09 #1
13 11207
JosAH
11,448 Expert 8TB
@dpsairam
Is your vector a Vector<Byte> or a Vector<Byte[]> or a Vector<byte[]>?

kind regards,

Jos
Aug 25 '09 #2
Is your vector a Vector<Byte> or a Vector<Byte[]> or a Vector<byte[]>?

can you tell me what is the difference between these three
Aug 25 '09 #3
JosAH
11,448 Expert 8TB
@dpsairam
A Vector<Byte> contains objects of type Byte; a Vector<Byte[]> contains arrays and each element is a Byte type object. A Vector<byte[]> contains arrays of bytes; they are of primitive type.

kind regards,

Jos
Aug 25 '09 #4
my vector is Vector<byte[]>
Aug 25 '09 #5
r035198x
13,262 8TB
So you have a lot of these byte arrays (byte[]) in a Vector. And you want to 'convert' them to just one byte[]? What are the rules for the conversion?
Aug 25 '09 #6
@r035198x
what rules..........????dint get u
Aug 25 '09 #7
@r035198x
see i have a byte array in Vector i want to extract that byte array from this vector
Aug 25 '09 #8
r035198x
13,262 8TB
Is there only one byte[] in the Vector then?
That simplifies matters somewhat.
Now all you need is to know what position in the Vector the array is at. Suppose the array is at index 41, then you simply do the simple
Expand|Select|Wrap|Line Numbers
1. int thePosition = 42;
2. byte[] theExtractedByteArray = (byte[])myVector.get(42);
3.
1.) If you use generics you won't need the cast.
2.) Why do you have Vector if you only have one byte[] to store?
3.) Why did you use Vector instead of ArrayList?
Aug 25 '09 #9
JosAH
11,448 Expert 8TB
@dpsairam
Suppose you have three arrays in the Vector with the following elements:

a1, a2 b1, b2, b3 and c1, c2

How do you want to store those seven elements in one array? There are several options and you know the 'rules', not us because we're not psychic.

kind regards,

Jos
Aug 25 '09 #10
JosAH
11,448 Expert 8TB
@r035198x
*ahem*

kind regards,

Jos ;-)
Aug 25 '09 #11
r035198x
13,262 8TB
41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41

Silly fingers, that should teach them to type of their own accord.
Aug 25 '09 #12
JosAH
11,448 Expert 8TB
@r035198x
I never have that.

kill regexp

Java ;-)
Aug 25 '09 #13
JosAH
11,448 Expert 8TB
@OP: I wonder how you got that byte[] in your Vector if you don't know how to get that element out of it.

kind regards,

Jos