Convert ByteBuffer to DoubleBuffer in Java
Description
The following code shows how to convert ByteBuffer to DoubleBuffer.
Example
//from w ww . j a v a2 s .co m
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
public class Main {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });
bb.rewind();
DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
System.out.println("Double Buffer");
while (db.hasRemaining())
System.out.println(db.position() + " -> " + db.get());
}
}
The code above generates the following result.