在java语言中,从fastutil library读取IntArrayList的最好方法是什么?
fastutil是一个用于提高性能的库,其性能高于标准库的集合类和算法。因此,在这种情况下,“最佳”意味着最好的性能。
我遵循advice in the fastutil docs并将我的集成开发环境(Eclipse)设置为在装箱发生时发出警告: Window ->首选项-> Java ->编译器->错误/警告->潜在编程问题->装箱和取消装箱转换->设置为警告
但是,Eclipse似乎省略了一些警告。有关详细信息,请参阅下面代码中的内容。
到目前为止,我遇到了以下用于迭代的替代方案:
IntArrayList list = ...;
// 1. for-loop-with-index-variable
for (int i = 0; i < list.size(); i++) {
// do something with list.getInt(i)
}
// 2. for-each-loop-with-wrapped
Integer value = list.getInt(0); // Eclipse correctly warns in this line
for (Integer element : list) { // autoboxing happens here somewhere, but Eclipse does NOT warn
// do something with element
}
// 3. for-each-loop-with-primitive
for (int element : list) { // Eclipse does NOT warn. Does autoboxing happen here?
// do something with element
}
// 4. forEach-method-with-consumer
list.forEach((int element) -> {
// do something with element
});
// 5. for-loop-with-IntIterator
for (IntIterator iter = list.iterator(); iter.hasNext();) {
// do something with iter.nextInt()
}发布于 2020-05-28 04:05:50
绝对是#1. :)
我必须添加更多的字符StackOverflow不会让我张贴这个。
https://stackoverflow.com/questions/61855626
复制相似问题