-2

How is it possible to store data (bytes) input like this: input data (bytes) : 01 23 45 and 67 89 10

At the end Arraylist row : [[01,23,45],[67,89,10]]

 // declaration
 List<List<Byte>> row = new ArrayList<List<Byte>>();
 List<Byte> myBytes = new ArrayList<Byte>();
 int j=0;

// code before this defines the arraylengt to cut the buffer in pieces of 3 bytes
// and clears the Mybytes arraylist to be able to fill the buffer with new values

if(arrayLength > 0)
{

    myBytes.add(value); // fill first arraylist (buffer) with byte value (for example: 01)

    if(arrayLength == 1) // when buffer myBytes is full (with values 01 23 45) write value to position j in the new arraylist
    {
        row.add(j,new ArrayList<Byte>());
        row.set(j,myBytes);
        j +=j;
    }
     arrayLength -= 1; // for cutting the buffer in pieces of 3 bytes
}

Thank you for helping me !!

A.student
  • 11
  • 1
  • 2
  • This has already been answered http://stackoverflow.com/questions/4126272/how-do-i-implement-nested-arraylist – rcbevans May 20 '13 at 17:30

3 Answers3

0

I'd suggest just using a matrix of size [n][3]. You can make sure that it stays as a byte by adding ifs, and must make it an int matrix that way it can have as many rows as you want.

0

Just use an Arraylist with an Array of Bytes new ArrayList<Byte[]>();. It's a good way to produce a [n][3]-Matrix.

pad
  • 239
  • 2
  • 8
0

I found the answer, use a arraylist to buffer the values convert to byte array and place them in a other arraylist. Thanks guys ! Note: Make shure u use myBytes.clear(); Here is my code:

if(bool == true)
{
 myBytes.add(value); // buffer        
 if(arrayLength == 1)
 {

    byte[] data = new byte[myBytes.size()];
    for (int i = 0; i < data.length; i++) 
    {
     data[i] = (byte) myBytes.get(i);
    }

    row.add(data);
 }      
 arrayLength -= 1;
}
A.student
  • 11
  • 1
  • 2