Arrays.asList(Data)
creates a list whose only element is an array of int (i.e. List<int[]>
). That's why Arrays.asList(Data).contains(num))
always returns false.
Try changing your array to :
Integer Data[] = new Integer[n];
This will make Arrays.asList(Data)
create a list of Integer
(List<Integer>
) containing all the integers of the original array, which is what you need.
The reason for this behavior is the Arrays.asList
expects one or more Object
s as its input. If you pass an array of Object
s (such as Integer[]
), it is equivalent to passing multiple Object
s. If, however, you pass an array of primitives (such as int[]
), the only Object
in your input is the array itself, so Arrays.asList()
creates a list whose only element is that array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…