title: Java - get element position in array
body: <p>I'm familiar with the ways I can get an element position in array, especially the ones showed here: <a href="https://stackoverflow.com/questions/4234827/element-position-in-array">Element position in array</a></p>
  
  <p>But my problem is I can't figure out how to convert this code to fit my needs.</p>
  
  <p>What I want to check is if a String has a match in an ArrayList and if so, what's the index of the String in the ArrayList.</p>
  
  <p>The annoying part is I managed to verify the String is in the ArrayList (see first line of my code)</p>
  
  <p>listPackages is the ArrayList</p>
  
  <p>current_package is the String I want to find its position in listPackages.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>if (listPackages.contains(current_package)) {
  
          int position = -1;
          for(int j = 0; j &lt; listPackages.size(); j++) {
  
              if(listPackages[j] == current_package) {
                position = j;
                    break;
                }
              }
      }
  </code></pre>
  
  <p>Would appreciate any help!</p>
  
  <p>Thanks!</p>