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.
> 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().