Home  >  Core Java

Example of DoubleBuffer, FloatBuffer and IntBuffer in Java

By Arvind Rai, November 16, 2013
DoubleBuffer is the buffer of double data type, FloatBuffer is the buffer of float data type. In the same way IntBuffer is the buffer of int data type. To get the instances of these classes we use

ByteBuffer.asDoubleBuffer()
ByteBuffer.asFloatBuffer()
ByteBuffer.asIntBuffer()

BufferTest.java
package com.concretepage.nio;
import java.io.FileNotFoundException;
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
public class BufferTest {
	public static void main(String[] args) throws FileNotFoundException {
           String s="12567.25";
	   DoubleBuffer db = ByteBuffer.wrap(s.getBytes()).asDoubleBuffer();
           System.out.println(db.get());
           
           FloatBuffer fb = ByteBuffer.wrap(s.getBytes()).asFloatBuffer();
           System.out.println(fb.get());
           
           IntBuffer ib = ByteBuffer.wrap(s.getBytes()).asIntBuffer();
           System.out.println(ib.get());
                      
	}
}
 
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us