或者,如果使用Java 8,则可以执行以下操作:
if(Arrays.stream(numbers).allMatch(x -> x == 2)) { // do something}基本上,使用Streams可以非常简洁地完成与集合/数组有关的所有操作。

或者,如果使用Java 8,则可以执行以下操作:
if(Arrays.stream(numbers).allMatch(x -> x == 2)) { // do something}基本上,使用Streams可以非常简洁地完成与集合/数组有关的所有操作。