title: Get indices of unique WebElements.getText() objects in an ArrayList
body: <p>I have an <code>ArrayList&lt;WebElements&gt;</code> whose elements all have some pieces of text. I'd like to store the indices of those <code>WebElements</code>, which contain unique pieces of text in a new <code>ArrayList&lt;Integer&gt;</code>. E.g. if the texts are (a,b,c,a,b,d) then I'd need (1,2,3,6).</p>
  <p>I tried getting the texts to <code>ArrayList&lt;String&gt; piecesOfText</code> with one <code>stream</code>, picking the uniques with another one into <code>ArrayList&lt;String&gt; piecesOfTextUnique</code>, then looping through <code>piecesOfTextUnique</code>and getting the indices of those pieces of text in <code>piecesOfText</code> via <code>indexOf()</code></p>
  <pre class="lang-java prettyprint-override"><code>ArrayList&lt;WebElement&gt; webElementsWithText=getWebElements();
  ArrayList&lt;String&gt; piecesOfText= new ArrayList&lt;&gt;();
  webElementsWithText.stream()
      .map(WebElement::getText)
      .forEach(piecesOfText::add);
  ArrayList&lt;String&gt; piecesOfTextUnique = (ArrayList&lt;String&gt;) piecesOfText.stream()
      .distinct()
      .collect(Collectors.toList());
  ArrayList&lt;Integer&gt; uniqueIndeces=new ArrayList&lt;&gt;();
  for (int i=0;i&lt; piecesOfTextUnique.size();i++) {
      uniqueIndeces.add(piecesOfText.indexOf(piecesOfTextUnique.get(i)));
  }
  </code></pre>
  <p>This one does the job, but can someone suggest a more concise/elegant solution?</p>