title: Find element position in a Java TreeMap
body: <p>I am working with a TreeMap of Strings <code>TreeMap&lt;String, String&gt;</code>, and using it to implement a Dictionay of words.</p>
  
  <p>I then have a collection of files, and would like to create a representation of each file in the vector space (space of words) defined by the dictionary.</p>
  
  <p>Each file should have a vector representing it with following properties:</p>
  
  <ul>
  <li>vector should have same size as dictionary</li>
  <li>for each word <strong>contained</strong> in the file the vector should have a <strong>1</strong> in the position corresponding to the word position in dictionary</li>
  <li>for each word <strong>not contained</strong> in the file the vector should have a <strong>-1</strong> in the position corresponding to the word position in dictionary</li>
  </ul>
  
  <p>So my idea is to use a <code>Vector&lt;Boolean&gt;</code> to implement these vectors. (This way of representing documents in a collection is called Boolean Model - <a href="http://www.site.uottawa.ca/~diana/csi4107/L3.pdf" rel="noreferrer">http://www.site.uottawa.ca/~diana/csi4107/L3.pdf</a>)</p>
  
  <p>The problem I am facing in the procedure to create this vector is that I need a way to find position of a word in the dictionary, something like this:</p>
  
  <pre><code>String key;
  int i = get_position_of_key_in_Treemap(key); &lt;--- purely invented method...
  </code></pre>
  
  <p>1) Is there any method like this I can use on a TreeMap?If not could you provide some code to help me implement it by myself?</p>
  
  <p>2) Is there an iterator on TreeMap (it's alphabetically ordered on keys) of which I can get position?</p>
  
  <p>3)Eventually should I use another class to implement dictionary?(If you think that with TreeMaps I can't do what I need) If yes, which?</p>
  
  <p>Thanks in advance.</p>
  
  <p>ADDED PART:</p>
  
  <p>Solution proposed by dasblinkenlight looks fine but has the problem of complexity (linear with dimension of dictionary due to copying keys into an array), and the idea of doing it for each file is not acceptable.</p>
  
  <p>Any other ideas for my questions?</p>