title: Accessing single values within a Map in Java
body: <p>firstly apologies if this has been asked before. I've searched and can't find anything similar so fingers crossed.</p>
  
  <p>Okay, what i'm trying to do is call the method of a single object within a TreeMap. I know the key values and am trying to use .get() but when i do, although it returns the object reference i can't do anything with it.</p>
  
  <p>Long story short is there a way to call a method from an object within a TreeMap, without having to iterate through the whole thing in the process? I feel like i'm misunderstanding something incredibly simple but the more i look at it the more i confuse myself. I understand how to iterate through and access all the values in the map using keySets etc. but my minds drawing a blank when it comes to this particular action.</p>
  
  <p>In case it makes a difference, the key's are Integers and the values are a class i've made myself. I'm trying to access the getName() method that i've made within the class for specific keys but can't seem to figure it out.</p>
  
  <p>Thanks</p>
  
  <p>EDIT: I'll attempt to post the code below, posting anything that may be relevant (sorry if any of it isn't)</p>
  
  <p>public class Battle
  {</p>
  
  <pre><code>TreeMap&lt;Integer, Enemy&gt; enemies = new TreeMap&lt;Integer, Enemy&gt;();
  TreeMap&lt;Integer, Character&gt; battleCharacters;
  int enemiesAlive;
  int totalXp;
  
  public Battle(TreeMap characters, int floorNumber)
  {
      createEnemies(floorNumber);
      battleCharacters = new TreeMap&lt;Integer, Character&gt;(characters);
  
      enemiesAlive = 6;
      totalXp = 0;
  
      for (Map.Entry&lt;Integer, Enemy&gt; entry : enemies.entrySet())
      {
          totalXp = totalXp + entry.getValue().getExperienceValue();
      }
  }
  </code></pre>
  
  <p>[...]</p>
  
  <pre><code>public void battleLoop()
  {
      System.out.println("Battle!");
      System.out.println("Your Party:");
      System.out.println(battleCharacters.get(1).statusReport()); //this doesn't work
      {
          //will be changed
          enemiesAlive--;
      }
  }
  
  public void battleReport()
  {
      for (int key : enemies.keySet())
      {
          enemies.get(key).statusReport(); //this works
      }
  }
  </code></pre>