Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Comparing two byte arrays for equality Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Comparing two byte arrays for equality" Watch "Comparing two byte arrays for equality" New topic
Author

Comparing two byte arrays for equality

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 757

Is there a utility class that provides for equality
comparison between 2 byte arrays ?


Regards,

Pho
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
How about using a method like this?
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
There is such a method in the java.util.Arrays class - its called 'equals' and takes the 2 byte arrays to be compared as arguments. The following is pasted straight from the API documentation:
equals
public static boolean equals(byte[] a,
byte[] a2)
Returns true if the two specified arrays of bytes are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements in the same order. Also, two array references are considered equal if both are null.
Parameters:
a - one array to be tested for equality.
a2 - the other array to be tested for equality.
Returns:
true if the two arrays are equal.
Hope this helps
Michael

------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Comparing two byte arrays for equality
 
Similar Threads
IP C-Class
javax.mail attachment not correctly encoded
Assignment To An Array Refrence
WA #1.....word association
Doubt About the output of this Question