Java列表对象,而不是一个数组 [英] Java List Object instead of an Array
问题描述
我哈瓦一个Java地图是这样的:
I hava a Java map like this:
Map<String, Object> data = new HashMap<String, Object>();
和我执行下面的操作是:
And I am performing following operation on it:
data.put("case_ids", new int[] { 31527 });
在哪里case_ids是第三方API的属性之一。然而,API抛出不正确API请求错误
,并建议我使用List对象而不是数组为:
Where case_ids is one of the attribute of 3rd party API. However, that API throws incorrect API request error
and suggests me to use List object instead of an Array for:
data.put(case_ids,新的INT [] {31527});
没有列出的专家,有什么建议?像 data.put(case_ids,新的列表[] {31527});
Not an expert of List, any suggestions? Like data.put("case_ids", new List[] { 31527 });
?
EDITED 的:扩展我的当前问题(避免转贴或类似的问题)。如果我有巨大的套以上put操作价值观,要创建已知值的列表。我不觉得这是提用逗号像31527,31528,31529,31530,31531,...等分隔值列表中选择一个正确的方式。我宁愿存储这个地方,只是称,作为这里的输入 - data.put(case_ids,新的INT [] {}输入);
。另外,就是可能没有文件怎么办?只是要避免文件的依赖。
EDITED: Extending my current question (to avoid repost or similar question). What if I have huge set of values for above put operation and want to create a list of known values. I do not feel that it is a correct way to mention the list of values separated by commas like 31527, 31528, 31529, 31530, 31531,..etc. I would rather store this somewhere and just call that as a input here - data.put("case_ids", new int[] { input });
. Also, is that possible to do without a file? Just want to avoid dependency on file.
推荐答案
您可以使用以下格式
data.put(case_ids,Arrays.asList(新的整数[] {} 31527))
;
如果你有一个整数数组,你所提到的意见,那么你可以使用一个
If you have an array of integers the one you have mentioned the comments then you can use
int [] cases = { 10,20,30};
data.put("case_ids", Arrays.asList(cases));
这篇关于Java列表对象,而不是一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!