In this case, the MAX is only 5, so I could check the duplicates one by one, but how could I do this in a simpler way? For example, what if the MAX has a value of 20? Thanks
Instead of doing all this create a LinkedHashSet
object and random numbers to it by Math.random()
function .... if any duplicated entry occurs the LinkedHashSet
object won't add that number to its List ... Since in this Collection Class no duplicate values are allowed .. in the end u get a list of random numbers having no duplicated values .... :D