fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.nio.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13.  
  14. int sizeOfDouble = 8;
  15. int numberOfDoubles = 4;
  16. ByteBuffer testBuf = ByteBuffer.allocateDirect(sizeOfDouble*numberOfDoubles);
  17.  
  18. testBuf.putDouble(0*sizeOfDouble, 1.0);
  19. testBuf.putDouble(1*sizeOfDouble, 2.0);
  20. testBuf.putDouble(2*sizeOfDouble, 3.0);
  21. testBuf.putDouble(3*sizeOfDouble, 4.0);
  22.  
  23. for (int i = 0; i < numberOfDoubles; ++i) {
  24. System.out.println("testBuf[" + i + "]: " + testBuf.getDouble(sizeOfDouble*i));
  25. }
  26.  
  27. }
  28. }
Success #stdin #stdout 0.09s 27924KB
stdin
Standard input is empty
stdout
testBuf[0]: 1.0
testBuf[1]: 2.0
testBuf[2]: 3.0
testBuf[3]: 4.0