# How to declare a queue of vector on Java?

## Recommended Posts

Hi friends! How to declare a queue of vector (of byte, fixed size) on Java? I want just every element is a byte array of 64 elements. Something like this: (this does not work) Queue<byte[64]> m_queue = new LinkedList<byte[64]>(); Must I use another class? For instance: Queue<Vector64Byte> m_queue = new LinkedList<Vector64Byte>(); I wouldn't like to do that. Thanks a lot for suggestions.

##### Share on other sites
Java arrays' size is defined on allocation, not on declaration, so you can't have a pointer of a fixed size. You can create a Vector64Byte class, or you can do something like that:
[source lang=java]public class LinkedList64Byte extends LinkedList<byte[]>{   public void add(int index,byte[] element)   {      if(element.size!=64)         throw new WrongSizeException();      super.add(index,element);   }}

##### Share on other sites
Quote:
 Original post by riruiloHi friends!How to declare a queue of vector (of byte, fixed size) on Java?I want just every element is a byte array of 64 elements.Something like this: (this does not work)Queue m_queue = new LinkedList();Must I use another class? For instance:Queue m_queue = new LinkedList();I wouldn't like to do that.

I suspect you mean an array, not a vector. If you meant a vector located in a 64D space with only 8 bits of precision per axis, you should create its class.

If you meant array, arrays are not vectors, each array must be allocated by new. (And each array would have Object overhead.)
...
...

Should do the trick.

Also don't prefix your variables, it's not C, it's Java, and it was bad even in C. If you desperately need a name decorator for some real reason, use postfix decoration.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628392
• Total Posts
2982420

• 10
• 9
• 19
• 24
• 11