0

My program has to pass a lot of arrays between threads. I want a collection that can accept an array, and then a contains method will specify whether a Set/Map contains the array (i.e. it is a duplicate or has already been processed by the thread). I assume this collection would have to use Arrays.equals(a1, a2), because the Object.equals() method will not work on arrays. Is it possible to write a collection that works like this, or would it fail when autoboxing from, say, int[] to Integer[]?

4

1 回答 1

6

使用Array覆盖hashCode()equals()喜欢的包装器Arrays.asList()

顺便说一句,您应该避免使用数组并尽可能选择集合。我还建议您将不可变数据结构用于多线程。在 Set 中使用可变对象或作为 Map 的键无论如何都是一个糟糕的主意。

于 2013-10-09T16:10:53.353 回答