Java列出基元类型的泛型语法 [英] Java List generics syntax for primitive types
本文介绍了Java列出基元类型的泛型语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个可增长的字节数组。即列表。
在c#中,通常会执行以下语法:
List< byte> mylist = new List< byte>();
在java中,这个语法不起作用,我搜索了一下,发现下面的代码 p>
List myList = new ArrayList();
但那不是我想要的。任何想法,我去哪里错了?
解决方案使用包装类
字节
: List< Byte> mylist = new ArrayList< Byte>();
然后,由于自动装箱,您仍然可以拥有:
for(byte b:mylist){
}
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?
解决方案
Use the wrapper class Byte
:
List<Byte> mylist = new ArrayList<Byte>();
Then, because of autoboxing, you can still have:
for (byte b : mylist) {
}
这篇关于Java列出基元类型的泛型语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文