Programming Articles - Page 2851 of 3368

DoubleBuffer asReadOnlyBuffer() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

101 Views

A read-only double buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.DoubleBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);          buffer.put(4.5D); ... Read More

DoubleBuffer compact() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

143 Views

The buffer can be compacted using the compact() method in the class java.nio.DoubleBuffer. This method does not require a parameter and it returns the new compacted DoubleBuffer with the same content as the original buffer. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(n);          buffer.put(1.2D);          buffer.put(3.9D);   ... Read More

DoubleBuffer allocate() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

101 Views

A new DoubleBuffer can be allocated using the method allocate() in the class java.nio.DoubleBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new DoubleBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);          buffer.put(4.5D);          buffer.put(1.2D);   ... Read More

DoubleBuffer duplicate() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

117 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.DoubleBuffer. This duplicate buffer is identical to the original buffer. The method duplicate() returns the duplicate buffer that was created.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer1 = DoubleBuffer.allocate(5);          buffer1.put(4.5D);          buffer1.put(1.2D);          buffer1.put(3.9D);          buffer1.put(7.5D); ... Read More

DoubleBuffer put() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

106 Views

The required value can be written at the current position of the buffer and then the current position is incremented using the method put() in the class java.nio.DoubleBuffer. This method requires a single parameter i.e. the value to be written in the buffer and it returns the buffer in which the value is inserted.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);     ... Read More

DoubleBuffer hasArray() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

115 Views

It can be checked if a buffer has the backing of an accessible double array by using the method hasArray() in the class java.nio.DoubleBuffer. This method returns true if the buffer has the backing of an accessible double array and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);          buffer.put(4.5D);          buffer.put(1.2D);         ... Read More

DoubleBuffer arrayOffset() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

92 Views

The offset of the first element of the buffer inside the buffer array is obtained using the method arrayOffset() in the class java.nio.DoubleBuffer. If the buffer backed by the array is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);          buffer.put(4.5D);          buffer.put(1.2D);          buffer.put(3.9D);         ... Read More

DoubleBuffer wrap() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

134 Views

A double array can be wrapped into a buffer using the method wrap() in the class java.nio.DoubleBuffer. This method requires a single parameter i.e. the array to be wrapped into a buffer and it returns the new buffer created. If the returned buffer is modified, then the contents of the array are also similarly modified and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       try {          double[] arr = { 8.7D, 1.5D, 3.2D, 7.4D, 5.9D ... Read More

FloatBuffer asReadOnlyBuffer() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

105 Views

A read-only float buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.FloatBuffer. The new buffer cannot have any modifications as it is a read-only buffer. However, the capacity, positions, limits etc. of the new buffer are the same as the previous buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          FloatBuffer buffer = FloatBuffer.allocate(5);          buffer.put(4.5F); ... Read More

FloatBuffer duplicate() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

108 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.FloatBuffer. This duplicate buffer is identical to the original buffer. The method duplicate() returns the duplicate buffer that was created.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          FloatBuffer buffer1 = FloatBuffer.allocate(n);          buffer1.put(4.5F);          buffer1.put(1.2F);          buffer1.put(3.9F);          buffer1.put(7.5F); ... Read More

Advertisements