Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > byte[] equals() only applies to same reference?

Reply
Thread Tools

byte[] equals() only applies to same reference?

 
 
Ong Hong Peow
Guest
Posts: n/a
 
      09-06-2004
Hi,

I've assumed that byte[] does equals with the content too, it's otherwise.
e.g.

byte[] testA = new byte[4];
testA[0] = 0;
testA[1] = (byte)0xac;
testA[2] = (byte)0xab;
testA[3] = (byte)0xde;

byte[] testB = new byte[4];
testB[0] = 0;
testB[1] = (byte)0xac;
testB[2] = (byte)0xab;
testB[3] = (byte)0xde;

System.out.println( testB.equals( testA ) );

prints "false"

How do you compare byte[]?
memcpy() .. kinda equvilant? ...

Hopefully not writing my own.

Thanks.


 
Reply With Quote
 
 
 
 
David Hilsee
Guest
Posts: n/a
 
      09-06-2004
"Ong Hong Peow" <(E-Mail Removed)> wrote in message
news:chgmvj$sfi$(E-Mail Removed)...
> Hi,
>
> I've assumed that byte[] does equals with the content too, it's otherwise.
> e.g.
>
> byte[] testA = new byte[4];
> testA[0] = 0;
> testA[1] = (byte)0xac;
> testA[2] = (byte)0xab;
> testA[3] = (byte)0xde;
>
> byte[] testB = new byte[4];
> testB[0] = 0;
> testB[1] = (byte)0xac;
> testB[2] = (byte)0xab;
> testB[3] = (byte)0xde;
>
> System.out.println( testB.equals( testA ) );
>
> prints "false"
>
> How do you compare byte[]?
> memcpy() .. kinda equvilant? ...
>
> Hopefully not writing my own.


Use java.util.Arrays.equals(). The java.util.Arrays class has all sorts of
methods that are useful when working with arrays.

--
David Hilsee


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataList ignores Styles when WebControlAdapter applies Sebastian Paul ASP .Net 3 08-17-2007 09:32 AM
Can roles be applies across applications? Larry Bud ASP .Net 1 06-28-2007 01:33 PM
This applies only to Virginians =?ISO-8859-1?Q?R=F4g=EAr?= Computer Support 35 06-27-2007 09:48 PM
Avoid calling non-final methods in a constructor: Applies to static methods too? Oliver Wong Java 14 06-13-2006 09:18 AM
FWSM "timeout conn" setting - Applies to inbound conn.s? dmcknigh@comcast.net Cisco 0 02-09-2005 10:47 PM



Advertisments