Arian
Arian

Reputation: 7719

Using Thread as a key in Collection

Is it possible to use Threads (Thread.getCurrentThread()) as keys in a collection (e.g. HashMap<Thread,Integer>). I know it's possible! I'd like to know that whether Java creates unique hashCodes for threads.

Upvotes: 4

Views: 1059

Answers (1)

irreputable
irreputable

Reputation: 45443

Yes, people did that before Java had ThreadLocal.

But now you probably should use ThreadLocal.

Upvotes: 8

Related Questions