#How do I search a 2D array for duplicate values?

1 messages · Page 1 of 1 (latest)

split niche
#

I'm using java.util.random to generate random x y coordinates and storing them in a 2D array. How would I search to make sure that there are not duplicate x y coordinates?

deft mesaBOT
#

<@&987246399047479336> please have a look, thanks.

deft mesaBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

uneven berry
#

you could keep track of values using a set, after you assign a value store it in hashset and before adding next one check if set contains it already

#

if yes then generate a new one and repeat

split niche
#

what would that code look like?

uneven berry
#

you'd need to keep track of both x and y values in seperate sets

#

i can't code it out for you, but could help if you have any particular question

split niche
#

ok thank you for the help 🙂