aspose file tools*
The moose likes Java in General and the fly likes Fastest way to compare strings? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Fastest way to compare strings?" Watch "Fastest way to compare strings?" New topic
Author

Fastest way to compare strings?

borf norton
Greenhorn

Joined: Aug 11, 2010
Posts: 4
Hi,
If I want to compare 2 strings, which are also already stored in byte[]'s in an object of mine... which is faster?

Arrays.compare(myStrByteArray1,myStrByteArray2);

OR

myStr.equals(myStr2);
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Compare in what way? First you'd have to write a compare() method in java.util.Arrays, so probably equals.

But if you followed the way most compare() methods operate, it would do something different than what equals() does, since equals() returns a boolean, and compare returns an int.

So, do you want to compare, or find out if equals? And what method were you actually referring to? And would it have been quicker to benchmark than to wait for an answer?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

We have a saying in the office: Suck it and see. ie have a go!

Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
borf norton wrote:If I want to compare 2 strings, which are also already stored in byte[]'s in an object of mine... which is faster?


Hi Borf,

You might want to have a look at String Comparison & Searches

Bye


"Eppur si muove!"
 
Consider Paul's rocket mass heater.
 
subject: Fastest way to compare strings?