What's the quickest way to compare strings in Java?

后端 未结 7 2080
情话喂你
情话喂你 2020-12-06 04:42

What\'s the quickest to compare two strings in Java?

Is there something faster than equals?

EDIT: I can not help much to clarify the problem.

I have

7条回答
  •  半阙折子戏
    2020-12-06 05:05

    If you can show that it's a significant bottleneck, which would surprise me, you could try

    s1.hashCode() == s2.hashCode() && s1.equals(s2)
    

    It might be a bit faster. It mightn't.

提交回复
热议问题