Compareto versus equals performance for strings equality

Hi

Just wanted to know whether compareto and equals method performance for checking whether the two strings are equal or not .

Which one is good with respect to bytecode , speed performance.

Im not asking for the difference, only asking which one is good to use most number of times for comparing two strings for equilaty.

Thanks.

[365 byte] By [ravibhushana] at [2007-11-27 2:30:37]
# 1
1) They are for two different purposes. Use them as intended. Any performance difference will almost certainly be negligible.2) Run tests.3) Look at the source.
jverda at 2007-7-12 2:44:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Hi Ya they are both for different purposes. No doubt.But which one is faster among the two for string equality?compareto or equals.thanksMessage was edited by: ravibhushan
ravibhushana at 2007-7-12 2:44:33 > top of Java-index,Java Essentials,Java Programming...
# 3
Read reply 1.
jverda at 2007-7-12 2:44:33 > top of Java-index,Java Essentials,Java Programming...
# 4
Ya, but look at reply #2 ;-)
DrLaszloJamfa at 2007-7-12 2:44:33 > top of Java-index,Java Essentials,Java Programming...
# 5

> Hi

>Ya they are both for different purposes. No doubt.

> t which one is faster among the two for string

> equality?

> compareto or equals.

> thanks

His point is that it doesn't matter. You shouldn't worry about optimization for small details like this. Unless you are profiling your code and find a large slowdown with that code, then don't worry about their performance. Use the one that best suits your purpose. If you want to know if they're equal, use equals(), if you want to know their order, use compareTo().

hunter9000a at 2007-7-12 2:44:34 > top of Java-index,Java Essentials,Java Programming...
# 6
> Ya, but look at reply #2 ;-)Great, now you've gotten us into an infinite loop. :)
hunter9000a at 2007-7-12 2:44:34 > top of Java-index,Java Essentials,Java Programming...
# 7
> > Ya, but look at reply #2 ;-)> > Great, now you've gotten us into an infinite loop. :)Yup. My internal JVM just generated a StackOverflowError.
DrLaszloJamfa at 2007-7-12 2:44:34 > top of Java-index,Java Essentials,Java Programming...