title: How to determine obj can be used in for loop
body: <p>I have try following code, but it return false.</p>
  
  <pre><code>package ro.idea.ex;
  
  import java.lang.reflect.Array;
  import java.util.Collection;
  
  /**
   * Created by roroco on 10/28/14.
   */
  public class Ex {
      public &lt;T&gt; boolean canWorkInForLoop(T o) {
          return o instanceof Collection || o instanceof Iterable || o instanceof Array;
      }
  
      public static void main(String[] args) {
          int[] arr = {1, 2};
          Object r = new Ex().canWorkInForLoop(arr);
          System.out.println("r:" + r + "\t\t" + new Exception().getStackTrace()[0].getFileName() + ":" + new Exception().getStackTrace()[0].getLineNumber());
      }
  }
  </code></pre>
  
  <p><strong>my question is:</strong></p>
  
  <p>How to determine all obj which can be used in for loop, like new int[], instance of ArrayList and other obj?</p>