title: Method to find all indices in List<Long> corresponding to some element
body: <p>Suppose I have an <code>long</code> called <code>X</code> and a <code>List&lt;Long&gt;</code> called <code>foo</code> which contains <code>X</code> as one non-unique element among many elements. What is the method I need to apply to find all the indices in <code>foo</code> that correspond to the <code>X</code>. This <code>foo</code> is not necessarily sorted (but a good answer may assume this if there is a specific method that requires sorting - I am interested in both sorted and unsorted cases). </p>
  
  <p>For example this could be the problem setup:</p>
  
  <pre><code>long X = 5L
  List&lt;Long&gt; foo = new ArrayList&lt;Long&gt;();
  foo.add(4L);
  foo.add(5L);
  foo.add(5L);
  foo.add(6L);
  foo.add(7L);
  </code></pre>
  
  <p>I want the method to accept <code>X</code> as an argument and return a list (or other object) that contains the indices <code>1</code> and <code>2</code>, since they correspond to the locations of <code>X</code> within <code>foo</code>.</p>
  
  <p>Trivially,</p>
  
  <pre><code>public static List&lt;Long&gt; locator(long target, List&lt;Long&gt; fooList) {
     List&lt;Long&gt; output = new ArrayList&lt;Long&gt;();
  
     for(int i = 0 ; i &lt; foo.size() ; i++) {
        if(foo.get(i) == target) {
           output.add(i);
        }
     }
  
     return output;
  }
  </code></pre>
  
  <p>But I want a faster way incase my <code>foo</code> is gigantically long.</p>