本文介绍了如何INT []转换为整数[]在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Java和非常混乱。

I'm new to Java and very confused.

我有一个大的数据集长度为4 INT [] 的,我想算的次数
这4个整数每个特定的组合出现。这是非常相似的文档中计数单词的频率。

I have a large dataset of length 4 int[] and I want to count the number of timesthat each particular combination of 4 integers occurs. This is very similar to counting word frequencies in a document.

我想创建一个地图< INT [],双> 映射作为列表迭代在每个INT []对运行计数,但地图没有按' t拍摄原始类型。

I want to create a Map<int[], double> that maps each int[] to a running count as the list is iterated over, but Map doesn't take primitive types.

所以我做了地图&LT;整数[],双&GT;

我的数据被存储为的ArrayList&LT; INT []&GT; 所以我循环应该是这样

my data is stored as an ArrayList<int[]> so my loop should be something like

ArrayList<int[]> data = ... // load a dataset`

Map<Integer[], Double> frequencies = new HashMap<Integer[], Double>();

for(int[] q : data) {

    // **DO SOMETHING TO convert q from int[] to Integer[] so I can put it in the map

    if(frequencies.containsKey(q)) {
    frequencies.put(q, tfs.get(q) + p);
    } else {
        frequencies.put(q, p);
    }
}

我不知道什么code,我需要在评论使这项工作到 INT [] 转换为整数[] 。或者,也许我根本搞不清楚这样做的正确方法。

I'm not sure what code I need at the comment to make this work to convert an int[] to an Integer[]. Or maybe I'm fundamentally confused about the right way to do this.

推荐答案

如果您想将 INT [] 转换为整数[] ,还没有做到这一点在JDK自动化的方式。然而,你可以做这样的事情:

If you want to convert an int[] to an Integer[], there isn't an automated way to do it in the JDK. However, you can do something like this:

int[] oldArray;

... // Here you would assign and fill oldArray

Integer[] newArray = new Integer[oldArray.length];
int i = 0;
for (int value : oldArray) {
    newArray[i++] = Integer.valueOf(value);
}

如果你有机会到库,那么你可以使用方法是这样的:

If you have access to the Apache lang library, then you can use the ArrayUtils.toObject(int[]) method like this:

Integer[] newArray = ArrayUtils.toObject(oldArray);

这篇关于如何INT []转换为整数[]在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 15:47