VOOZH about

URL: https://www.geeksforgeeks.org/java/bytebuffer-getdouble-method-in-java-with-examples/

⇱ ByteBuffer getDouble() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ByteBuffer getDouble() method in Java with Examples

Last Updated : 17 Jun, 2019
getDouble()
The getDouble() method of java.nio.ByteBuffer class is used to read the next eight bytes at this buffer's current position, composing them into a double value according to the current byte order, and then increments the position by eight. Syntax:
public abstract double getDouble()
Return Value: This method returns the double value at the buffer's current position Throws: This method throws BufferUnderflowException if the buffer’s current position is not smaller than its limit, then this exception is thrown. Below are the examples to illustrate the getDouble() method: Examples 1:
Output:
Original ByteBuffer: 
1234.3456 2884.4444 

Byte Value: 1234.3456

Next Byte Value: 2884.4444
Examples 2:
Output:
Original ByteBuffer: 
1234.3456 2884.4444 

Byte Value: 1234.3456

Next Byte Value: 2884.4444

there are fewer than eight bytes remaining in this buffer
Exception Thrown : java.nio.BufferUnderflowException
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#getDouble--
getDouble(int index)
The getDouble(int index) method of ByteBuffer is used to read eight bytes at the given index, composing them into a double value according to the current byte order. Syntax :
public abstract double getDouble(int index)
Parameters: This method takes index as parameter which is the index from which the Byte will be read. Return Value: This method returns The double value at the given index Exception: This method throws IndexOutOfBoundsException. If index is negative or not smaller than the buffer’s limit this exception is thrown. Below are the examples to illustrate the getDouble(int index) method: Examples 1:
Output:
Original ByteBuffer: 
1234.3456 2884.4444 

Byte Value: 1234.3456

Next Byte Value: 2884.4444
Examples 2:
Output:
Original ByteBuffer: 
1234.3456 2884.4444 

Byte Value: 1234.3456

index is negative or smaller than the buffer's limit, minus seven
Exception Thrown : java.lang.IndexOutOfBoundsException
Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/ByteBuffer.html#getDouble-int-
Comment