• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList of double arrays  RSS feed

 
matecno alex
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have an ArrayList of double arrays, how do I check if there is any similarity between these double arrays in the minimal time possible? (Two arrays are considered similar if all their elements are the same)

Thanks
 
Paweł Baczyński
Bartender
Posts: 2085
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out: Arrays#equals(double[], double[])

And welcome to the Ranch!
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:Check this out: Arrays#equals(double[], double[])

That would require the two arrays to contain the same elements in the same order.
If the order is not important (the OP didn't mention it), I would look at using the Arrays.asList and List.containsAll methods.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't worry about doing it "in the minimum time possible", but in the clearest way for someone else (or even yourself in 3 months) to understand the code. If you need to compare a million pairs of arrays, and by using clever tricks you save 1 microsecond per check, your total savings is one second.

but if it takes you an additional eight hours to understand your code next month, you've lost out.

The first rule of writing code is "do it right". ONLY if once you've done that and you have a DOCUMENTED reason to make it faster should you look at improving things.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!