I have `HashSet<Integer>` `A` and `B` I want to compare to get a numeric value how similar they are (e.g. 0.9 if 90% of `A` and `B` are the same). What is the best (fastest) way to do this in java or groovy?

My naive way to do this is to get all equal elements from `A` and `B` and divide the size of them through the original size of `A`. Is there any reason (speed e.g.) why this wouldn't work properly? Generally speaking I would prefer any already implemented way to get the similarity.

Note: Comparing `1, 2` to `12` should be 0% similarity.