Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Key HashSet?

Tags:

java

hashset

I need a HashSet implementation where the elements are a pair of Integers
eg. Set s = { {1,2} , {3,4} , {1,4}}. Here the set s has 3 elements.

This kind of two key HashSet is needed in many situations like, I have a relation in my database where the candidate key is a combination of two columns.
Is there some library which already provides this? If no such implementation is available, then rather then implementing the entire data structure from scratch, will it be easier (and efficient?) to extend the HashSet implementation in Java?

like image 639
athena Avatar asked Apr 10 '10 10:04

athena


1 Answers

For this requirement I would create a data holder with the 2 integers as attributes and provide equals and hashcode implementations. Then put those objects in the Set.

like image 72
rsp Avatar answered Sep 27 '22 00:09

rsp