对比元素在重复一个数组 [英] Compare elements in an array for duplicates

查看:143
本文介绍了对比元素在重复一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成Java 5位数 INT 阵列和我有从哪里开始的麻烦。数字的无阵列中可以是重复的。我可以生成随机数是罚款,但只是无法弄清楚如何将数字相互比较和替换任何重复。

I am trying to generate a 5 digit int array in Java and am having trouble on where to start. None of the numbers in the array can be duplicates. I can generate random numbers for it fine but just cant figure out how to compare the numbers to each other and replace any duplicates.

推荐答案

您可以使用java.util.Set中,而不是一个数组,因为它是保证只有独特的元素。

You can use a java.util.Set instead of an array as it is guaranteed to have only unique elements.

这篇关于对比元素在重复一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆