title: Java Using iterator for arraylist how do you get index
body: <p>If i'm using Iterator how do i get the index in which my condition is met?  <code>iterator.next()</code> gives me one after so I can minus one but I figure this is right way to do this? </p>
  
  <pre><code>public static int getSomething()
      int tempposition = 1;
              Iterator&lt;Item&gt; iterator = data.iterator();
              while (iterator.hasNext())
              {
                  if (iterator.next().getTitle().equals("Something"))
                  {
                      tempposition = iterator.next().getPosition();
                  }
  
  
              }
  
  return tempposition - 1;
  </code></pre>
  
  <p>What I found to be correct code for my situation.</p>
  
  <pre><code>public static int getSomething()
      {
          int tempposition = 1;
  
          Iterator&lt;Item&gt; iterator = data.iterator();
  
          while (iterator.hasNext())
          {
            Item item = iterator.next();
  
                if (item.getTitle().equals("Something"))
              {
                  tempposition = item.getPosition();
              }
  
          }
  
  
          Log.d(TAG, "tempposition is " + tempposition );
          return tempposition ;
  
  
      }
  </code></pre>