如何在数组数组中找到独特的数组?
我正在尝试检查数组数组是否有重复值。最终目标将是一个 if 语句,内容是:
if (arr 没有重复值) {继续代码}
int [][] arr = new int[3][2];
int [] x = new int[1];
arr[0][0] = 1;
arr[0][1] = 1;
arr[1][0] = 1;
arr[1][1] = 2;
arr[2][0] = 1;
arr[2][1] = 2;
x = arr.getUnique(); /I assume it'll use getUnique() but I can't even get that to work
任何帮助都会很棒!谢谢
I'm trying to check whether an array of arrays has any duplicate values. The end goal would be an if statement saying:
if (arr does NOT have duplicate values) {continue code}
int [][] arr = new int[3][2];
int [] x = new int[1];
arr[0][0] = 1;
arr[0][1] = 1;
arr[1][0] = 1;
arr[1][1] = 2;
arr[2][0] = 1;
arr[2][1] = 2;
x = arr.getUnique(); /I assume it'll use getUnique() but I can't even get that to work
Any help would be awesome! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 有一个 HashSet 您可以使用有一个没有重复的集合。
找到一种方法将数组转换为
HashSet
并比较它们的元素数量。如果它们具有相同数量的元素,则数组中的每个元素都是唯一的,如果 HashSet 较小,则意味着一些重复项已被删除。Java has a HashSet you can use to have a collection without duplicates.
Find a way to convert your array into a
HashSet
and compare the number of their elements. If they have the same number of elements, each element in your array is unique, if the HashSet is smaller, it means some duplicates have been removed.您可以创建自己的辅助函数,如下所示:
You could create a helper function of your own like this: