title: How to find the position of elements in ArrayList in Java?
body: <p>My code match the character entered by user with ArrayList having characters, and display results. I used loop and IF statement to print different results for matched characters and unmatched characters. I used Array.Contains() method to compare the user input with ArrayList elements. I am trying to print the position of the element in the ArrayList when matched.</p>
  
  <p>For example: ArrayList has: [a, b, c, d] and the positions (0 for a, 1 for b, 2 for c and 3 for d). How can I do it programatically to print the position of the element matched?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>ArrayList&lt;Character&gt; charsList = new ArrayList&lt;Character&gt;();
  
  for (int i = 0; i &lt; wordsList[0].length(); i++) {
      charsList.add(wordsList[0].charAt(i));
  }
  
  for (int i = 0; i &lt; wordsList[0].length(); i++) {
      inputValue = input.next().charAt(0);
      if (charsList.contains(inputValue)) {
          System.out.println("Matched!");  
      }
      else {
          System.out.println("Not Matched!");
      }   
  }
  </code></pre>