This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Comparing two arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing two arrays" Watch "Comparing two arrays" New topic
Author

Comparing two arrays

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 281
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

Joined: Jun 19, 2001
Posts: 547
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 281
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing two arrays
 
Similar Threads
Strings
What are two dimensional arrays?
Wats the O/P...
javax.mail attachment not correctly encoded
2D array