title: Get the IDs of all objects in a list
body: <p>I have a class like this:</p>
  
  <pre><code>class Foo {
      String bar
  }
  </code></pre>
  
  <p>I am trying to get the IDs of all the <code>Foo</code> objects whose <code>bar</code> String is in the list <code>bars</code>.  I have tried it several ways, always receiving the same error:</p>
  
  <pre><code>java.lang.String cannot be cast to java.util.Collection
  </code></pre>
  
  <p>Some of the things I have tried:</p>
  
  <pre><code>def ids = Foo.findAllByBarInList( bars )*.id
  def ids = Foo.findAllByBarInList( bars ).collect{ it.id }
  def ids = Foo.findAllByBarInList( bars ).collect{ it -&gt; it?.id }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I was making <code>bars</code> with <a href="http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#split%28%29">split</a> so it was an array, not a list. It threw me off because <code>Foo.findAllByBarInList( bars )</code> returned my <code>Foo</code> objects just fine, only when I tried to collect the ids did it fail.  I now make <code>bars</code> with <a href="http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#tokenize%28%29">tokenize</a> instead and all is well.</p>