• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList of double arrays

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this out: Arrays#equals(double[], double[])

And welcome to the Ranch!
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic