Mapping of strings to integers
<p>What is the easiest way in Java to map strings (Java <code>String</code>) to (positive) integers (Java <code>int</code>), so that</p>

<ul>
<li>equal strings map to equal integers, and</li>
<li>different strings map to different integers?</li>
</ul>

<p>So, similar to <code>hashCode()</code> but different strings are required to produce different integers. So, in a sense, it would be a hasCode() without the collision possibility.</p>

<p>An obvious solution would maintain a mapping table from strings to integers,
and a counter to guarantee that new strings are assigned a new integer. I'm just wondering
how is this problem usually solved.
Would also be interesting to extend it to other objects than strings.</p>
