Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java List generics syntax for primitive types

I want to make a growable array of bytes. I.e a list. In c# would usally do the following syntax

List<byte> mylist = new List<byte>();

where as in java this syntax does not work and I have googled around and found the below code

List myList = new ArrayList();

but that is not what I want. Any idea's where I am going wrong?

like image 607
Ciarán Avatar asked Feb 20 '10 11:02

Ciarán


2 Answers

You could also use TByteArrayList from the GNU Trove library.

like image 171
finnw Avatar answered Sep 22 '22 20:09

finnw


Use the wrapper class Byte:

List<Byte> mylist = new ArrayList<Byte>();

Then, because of autoboxing, you can still have:

for (byte b : mylist) {

}
like image 26
Bozho Avatar answered Sep 23 '22 20:09

Bozho