title: What is better/faster in Java: 2 method calls or 1 object call
body: <p>I'm afraid this is a terribly stupid question. However, I can't find an answer to it and therefore require some help :)</p>
  
  <p>Let's start with a simplification of my real problem:</p>
  
  <p>Assume I have a couple of boxes each filled with a mix of different gems.</p>
  
  <p>I'm now creating an object gem which has the attribute colour and a method getColour to get the colour of the gem.
  Further I'm creating an object box which has a list of gems as attribute and a method getGem to get a gem from that list.</p>
  
  <p>What I want to do now is to count all gems in all boxes by colour. Now I could either do something like</p>
  
  <pre><code>int sapphire = 0;
  int ruby = 0;
  int emerald = 0;
  
  for(each box = i)
      for(each gem = j)
          if(i.getGem(j).getColour().equals(“blue”)) sapphire++;
          else if(i.getGem(j).getColour().equals(“red”)) ruby++;
          else if(i.getGem(j).getColour().equals(“green”)) emerald++;
  </code></pre>
  
  <p>or I could do</p>
  
  <pre><code>int sapphire = 0;
  int ruby = 0;
  int emerald = 0;
  String colour;
  
  for(each box = i)
      for(each gem = j)
          colour = i.getGem(j).getColour();
          if(colour.equals(“blue”)) sapphire++;
          else if(colour.equals(“red”)) ruby++;
          else if(colour.equals(“green”)) emerald++;
  </code></pre>
  
  <p>My question is now if both is essentially the same or should one be preferred over the other? I understand that a lot of unnecessary new string objects are produced in the second case, but do I get a speed advantage in return as colour is more “directly” available?</p>