Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
或者有吗?
我只有
int[] results
并想检查数组中的每个元素是否具有相同的 int 值。
(是的,我可以遍历它们)。
无需循环,只需将数组转换为 Set 对象,然后检查其长度,如果长度为 1,则数组中的所有内容都相等。
Integer[] myArray = ...; assertThat(new HashSet(Arrays.asList(myArray)).size(), is(1));