0

I need to create a set of android objects (BluetoothDevice objects). Of course, I chose a Set because I don't want any duplicate in my Collection.

My problem is the following : When I do a bluetooth discovery in Android I receive twice the same device (for e.g. device WINIE7, with mac 80:22:00:22:00), and the references are not the same, so both of them are added in the Set.

Would it be possible to create a kind of "Comparator" to my Set, which would tell to compare the mac addresses ?

Thanks.

psv
  • 2,957
  • 5
  • 28
  • 62

1 Answers1

0

Override the equals method of your BluetoothDevice object to return true if the hashes are equal. Also override the hashCode method to comply with its specification, see this question.

Community
  • 1
  • 1
nhaarman
  • 94,943
  • 53
  • 240
  • 273
  • I don't have any access on BluetoothDevice object. This object comes from Android API... – psv Feb 05 '15 at 09:09