• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing two arrays

 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to compare the contents of two arrays, e.g. that two String arrays contain the same element values in the same order?
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.Arrays contains useful methods related to .... Arrays :-)
there are various methods to compare arrays (boolean arrays, int arrays, ...)

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html

pascal
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you care about order, some interesting approaches come up. If they are SORTED this works nicely:

For lists that are NOT sorted, I have an old Pascal program that looks ahead a certain distance (could be to the end on arrays) to decide which one has elements that are not in the other.

Late breaking thought: My Text Diff program compares arrays of strings, more or less.
 
Jay Damon
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. The equals method on the Arrays class was what I needed. I had looked at the Arrays class prior to posting this question but for some reason overlooked the equals method at that time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic