Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fastest way to compare strings?

 
borf norton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a saying in the office: Suck it and see. ie have a go!

 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic