Creating an array of 40 bytes

Joined
Oct 28, 2006
Messages
1
Reaction score
0
Hi,

I would like to send a datagram packet containing two parts of data totaling 40 bytes long.

There are two pieces of data that will be read from the command line.

The first is a name (30 bytes) and the second is a number (10 bytes).

I thought about:

Code:
byte [] name = args[0].getBytes();
byte [] number = args[1].getBytes();

and then concating the arrays but i wondered if there was a way to put both pieces of data in one array straight away.

Any ideas?

Thanks
 
Joined
Oct 29, 2006
Messages
2
Reaction score
0
Yes, here's my idea :smile: :

Code:
byte[] name = args[0].getBytes();
byte[] number = args[1].getBytes();

byte[] nameNumber = new byte[name.length + number.length];

System.arraycopy(name, 0, nameNumber, 0, name.length);
System.arraycopy(number, 0, nameNumber, name.length, number.length);

// and now the nameNumber will contain name and number respectively.


Regards,

SK - jAlexander
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top