avatar
s*y
1
Hi I have a stupid question: how to convert an array to a list?
For example, I want to convert double [] a = {1.0, 2.0}; to a type of List<
Double>.
How to do it without using a loop to visit every element in the array?
I tried Arrays.asList but got an "incompatible type" error message.
Thanks
avatar
t*y
2
Double [] a = {1.0,2.0}; should fix it.

【在 s*******y 的大作中提到】
: Hi I have a stupid question: how to convert an array to a list?
: For example, I want to convert double [] a = {1.0, 2.0}; to a type of List<
: Double>.
: How to do it without using a loop to visit every element in the array?
: I tried Arrays.asList but got an "incompatible type" error message.
: Thanks

avatar
g*g
3
Arrays.asList(a)

【在 s*******y 的大作中提到】
: Hi I have a stupid question: how to convert an array to a list?
: For example, I want to convert double [] a = {1.0, 2.0}; to a type of List<
: Double>.
: How to do it without using a loop to visit every element in the array?
: I tried Arrays.asList but got an "incompatible type" error message.
: Thanks

avatar
F*n
4
If you have to convert from a primitive array, there's no way other than
loop it.

【在 s*******y 的大作中提到】
: Hi I have a stupid question: how to convert an array to a list?
: For example, I want to convert double [] a = {1.0, 2.0}; to a type of List<
: Double>.
: How to do it without using a loop to visit every element in the array?
: I tried Arrays.asList but got an "incompatible type" error message.
: Thanks

avatar
b*y
5
right, I second Foxman. You just need to loop and copy each reference out to
the list.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。