Connecting Tech Pros Worldwide Help | Site Map

How convert from vector to Byte array

Newbie
 
Join Date: Jul 2008
Posts: 6
#1: Aug 25 '09
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...

--------------------------------------------------------------------------------
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by dpsairam View Post

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...

--------------------------------------------------------------------------------

Is your vector a Vector<Byte> or a Vector<Byte[]> or a Vector<byte[]>?

kind regards,

Jos
Newbie
 
Join Date: Jul 2008
Posts: 6
#3: Aug 25 '09

re: How convert from vector to Byte array


Quote:
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
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by dpsairam View Post

can you tell me what is the difference between these three

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
Newbie
 
Join Date: Jul 2008
Posts: 6
#5: Aug 25 '09

re: How convert from vector to Byte array


my vector is Vector<byte[]>
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Aug 25 '09

re: How convert from vector to Byte array


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?
Newbie
 
Join Date: Jul 2008
Posts: 6
#7: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by r035198x View Post

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?

what rules..........????dint get u
Newbie
 
Join Date: Jul 2008
Posts: 6
#8: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by r035198x View Post

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?

see i have a byte array in Vector i want to extract that byte array from this vector
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#9: Aug 25 '09

re: How convert from vector to Byte array


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?
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#10: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by dpsairam View Post

what rules..........????dint get u

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
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#11: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by r035198x View Post

Suppose the array is at index 41, then you simply do the simple

int thePosition = 42;
byte[] theExtractedByteArray = (byte[])myVector.get(42);

*ahem*

kind regards,

Jos ;-)
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#12: Aug 25 '09

re: How convert from vector to Byte array


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.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#13: Aug 25 '09

re: How convert from vector to Byte array


Quote:

Originally Posted by r035198x View Post

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.

I never have that.

kill regexp

Java ;-)
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#14: Aug 25 '09

re: How convert from vector to Byte array


@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

ps. I noticed you reporting this thread; better concentrate on being clear so that we can answer your extremely vague question instead.
Reply