Fastest way to check if a List contains a unique String

前端 未结 10 985
天涯浪人
天涯浪人 2020-12-13 11:43

Basically I have about 1,000,000 strings, for each request I have to check if a String belongs to the list or not.

I\'m worried about the performance, so what\'s the

10条回答
  •  既然无缘
    2020-12-13 12:33

    Not only for String, you can use Set for any case you need unique items.

    If the type of items is primitive or wrapper, you may not care. But if it is a class, you must override two methods:

    1. hashCode()
    2. equals()

提交回复
热议问题