title: How to convert int[] to ByteBuffer in Java?
body: <p>as the title already says, I need to convert an int[] to a ByteBuffer in Java. Is there a recommended way to do this ?</p>
  
  <p>I want to pass the ByteBuffer over JNI to C++. What do I have to look out for regarding any specific endian conversions in this case ?</p>
  
  <p>Edit: Sorry, I mistakenly wrote ByteArray but meant the type ByteBuffer.</p>
  
  <p>Edit: Sample code:</p>
  
  <p>I stripped out the unnecessary parts. I call a Java function over JNI from c++ to load a resource and pass it back to c++ as bytebuffer. It works with various other resources. Now I have an "int []" and would like to know if there is an elegant way to convert it to a bytebuffer or if I have to go the oldfashioned way and fill it in a for loop.</p>
  
  <pre><code>ByteBuffer  resource= null;
  resource = ByteBuffer.allocateDirect((x*y+2)*4).order(ByteOrder.nativeOrder());
  .
  .
  ByteBuffer GetResourcePNG(String text)
  {
      .
      .
      int []  pix;
      map.getPixels(pix,0,x,0,0,x,y);
  
      return resource;
  }
  </code></pre>