title: Get an element from and Arraylist according to an attribute - Java
body: <p>I have an Arraylist of a class "Variable". Each "Variable" object has a name (String) and a value (int).
  Is there an efficient way to retrieve the object in the ArrayList that has a specific name?
  ie:</p>
  
  <pre><code>ArrayList&lt;Variable&gt; vars = new ArrayList&lt;Variable&gt;();
  //Fill with values here//
  for (int j = 0; j &lt; vars.size(); j++) {
      String nName = vars.get(j).getName();
      //not real code, but what I would like
      return vars.get(element.getName().equals(nName));
  }
  </code></pre>
  
  <p>At the moment I am trying to accomplish this with lots of for loops and as well as looking ugly it isn't efficient.
  Thanks! </p>