I want to operate over array of integers, and I can solve the problem using hashtable
. I want to store the ellements of the array as Key
but for Value
I really don't care what will be stored there. In such case how should I create my hashtable? My approach is just to set value as 0 for each element like this:
Hashtable<Integer, Integer> ht = new Hashtable<Integer, Integer>();
for (int i = 0; i < arr.length; i++) {
ht.put(arr[i], 0);
}
Is there any convention what should I do in such cases? For example, is it better to set Value
as Boolean
and respectively true
for all inserted elements? Once again, for me it really doesn't matter what will be stored in Value
. I just want to know what is the best approach in such cases.