DoubleBuffer get() methods in Java with Examples Last Updated : 04 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The get() method of java.nio.DoubleBuffer Class is used to reads the double at the given buffer’s current position, and then increments the position. Syntax: public abstract double get() Return Value: This method returns the double value at the buffer’s current position. Exception: 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 get() method: Examples 1: Java // Java program to demonstrate // get() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the FloatBuffer int capacity = 5; // Creating the FloatBuffer try { // creating object of floatbuffer // and allocating size capacity DoubleBuffer fb = DoubleBuffer.allocate(capacity); // putting the value in Doublebuffer fb.put(8.56D); fb.put(9.61D); fb.put(1.24D); fb.rewind(); // print the DoubleBuffer System.out.println("Original DoubleBuffer: " + Arrays.toString(fb.array())); // Reads the double at this buffer's current position // using get() method double value = fb.get(); // print the double value System.out.println("\nDouble Value: " + value); // Reads the double at this buffer's next position // using get() method double value1 = fb.get(); // print the double value System.out.print("\nNext double Value: " + value1); } catch (IllegalArgumentException e) { System.out.println("\nIllegalArgumentException catched"); } catch (ReadOnlyBufferException e) { System.out.println("\nReadOnlyBufferException catched"); } catch (BufferUnderflowException e) { System.out.println("\nException throws: " + e); } } } Output: Original DoubleBuffer: [8.56, 9.61, 1.24, 0.0, 0.0] Double Value: 8.56 Next double Value: 9.61 Examples 2: Java // Java program to demonstrate // get() method import java.nio.*; import java.util.*; public class GFG { public static void main(String[] args) { // Declaring the capacity of the DoubleBuffer int capacity = 3; // Creating the DoubleBuffer try { // creating object of Doublebuffer // and allocating size capacity DoubleBuffer fb = DoubleBuffer.allocate(capacity); // putting the value in Doublebuffer fb.put(8.56F); fb.put(9.61F); // print the DoubleBuffer System.out.println("Original DoubleBuffer: " + Arrays.toString(fb.array())); // Reads the Double at this buffer's current position // using get() method Double value = fb.get(); // print the Double value System.out.println("\nDouble Value: " + value); // Reads the Double at this buffer's next position // using get() method System.out.print("\nsince the buffer current" + " position is incremented"); System.out.print(" to greater than its limit "); Double value1 = fb.get(); // print the Double value System.out.print("\nNext Double Value: " + value1); } catch (IllegalArgumentException e) { System.out.println("\nIllegalArgumentException catched"); } catch (ReadOnlyBufferException e) { System.out.println("\nReadOnlyBufferException catched"); } catch (BufferUnderflowException e) { System.out.println("\nException throws: " + e); } } } Output: Original DoubleBuffer: [8.5600004196167, 9.609999656677246, 0.0] Double Value: 0.0 since the buffer current position is incremented to greater than its limit Exception throws: java.nio.BufferUnderflowException Reference: https://docs.oracle.com/javase/9/docs/api/java/nio/DoubleBuffer.html#get-- Comment More infoAdvertise with us Next Article DoubleBuffer get() methods in Java with Examples P pawan_asipu Follow Improve Article Tags : Misc Java Java-Functions Java-NIO package Java-DoubleBuffer +1 More Practice Tags : JavaMisc Similar Reads ByteBuffer get() method in Java with Examples get() The get() method of java.nio.ByteBuffer class is used to read the byte at the buffer's current position, and then increments the position. Syntax : public abstract byte get() Return Value: This method returns the byte at the buffer's current position. Throws: This method throws BufferUnderflow 6 min read DoubleBuffer flip() methods in Java with Examples The flip() method of java.nio.DoubleBuffer Class is used to flip this buffer. By flipping this buffer, it meant that the buffer will be trimmed to the current position and then the position will be changed to zero. During this process, if any mark is there on the buffer, then that mark will be autom 2 min read DoubleBuffer mark() methods in Java with Examples The mark() method of java.nio.DoubleBuffer Class is used to mark the current position of this DoubleBuffer as the mark of this buffer. Syntax: public DoubleBuffer mark() Return Value: This method returns this DoubleBuffer after setting the buffer's mark at the current position. Below are the example 2 min read ByteBuffer getInt() method in Java with Examples getInt() The getInt() method of java.nio.ByteBuffer class is used to read the next four bytes at this buffer's current position, composing them into an int value according to the current byte order, and then increments the position by four. Syntax: public abstract int getInt() Return Value: This met 5 min read DoubleBuffer limit() methods in Java with Examples The limit() method of java.nio.DoubleBuffer Class is used to modify this DoubleBuffer's limit. This method takes the limit to be set as the parameter and sets that as the new limit of this Buffer. If the mark of this Buffer is already defined and is larger than the new specified limit, then this new 2 min read Like