How do I implement a string comparison in Java that takes the same amount of time no matter whether they match or where a mismatch (if any) occurs?

后端 未结 6 1826
情书的邮戳
情书的邮戳 2020-12-11 04:30

I want to implement a String comparison function that doesn\'t take a different amount of time depending on the number of characters that match or the position

6条回答
  •  盖世英雄少女心
    2020-12-11 04:48

    You can do constant time string comparisons if you intern your strings. Then you can compare them with == operator resulting in a constant time equality check.

    Read this for further detials

提交回复
热议问题