Check if a collection contains an object, comparing by reference

前端 未结 6 1577
猫巷女王i
猫巷女王i 2020-12-29 22:13

The Collection.contains() method check if a collection contains a given object, using the .equals() method to perform the comparison.

From Java7 Javadoc

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 23:00

    There is no way to check that the way you are trying to do. Without iterating through collection you cannot check that the object point to same reference or not.

    AFAIK, No (At least a clean way).

提交回复
热议问题