Found 9326 Articles for Object Oriented Programming

DoubleBuffer wrap() method in Java

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

68 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

49 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

69 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

FloatBuffer equals() method in Java

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

78 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.FloatBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and same sequence of elements. The method equals() returns true if the buffers are equal 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 {          FloatBuffer buffer1 = FloatBuffer.allocate(n);          buffer1.put(4.5F); ... Read More

FloatBuffer array() method in Java

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

135 Views

A float array for the buffer can be obtained using the method array() in the class java.nio.FloatBuffer. If the returned array is modified, then the contents of the buffer are also similarly modified and vice versa. 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 {          FloatBuffer buffer = FloatBuffer.allocate(n);          buffer.put(4.5F);          buffer.put(1.2F); ... Read More

FloatBuffer put() method in Java

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

87 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.FloatBuffer. 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 {          FloatBuffer buffer = FloatBuffer.allocate(n);     ... Read More

FloatBuffer wrap() method in Java

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

84 Views

A float array can be wrapped into a buffer using the method wrap() in the class java.nio.FloatBuffer. 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 {          float[] arr = { 8.7F, 1.5F, 3.2F, 7.4F, 5.9F ... Read More

FloatBuffer get() method in Java

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

124 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.FloatBuffer. This method returns the value that is at the current buffer position. Also, the BufferUnderflowException is thrown if underflow situation occurs.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(n);          buffer.put(4.5F);          buffer.put(1.2F);       ... Read More

FloatBuffer slice() method in Java

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

78 Views

A new FloatBuffer with the content as a shared subsequence of the original FloatBuffer can be created using the method slice() in the class java.nio.FloatBuffer. This method returns the new FloatBuffer that is read-only if the original buffer is read-only and direct if the original buffer is direct.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);       ... Read More

FloatBuffer hasArray() method in Java

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

73 Views

It can be checked if a buffer has the backing of an accessible float array by using the method hasArray() in the class java.nio.FloatBuffer. This method returns true if the buffer has the backing of an accessible float 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 {          FloatBuffer buffer = FloatBuffer.allocate(5);          buffer.put(4.5F);          buffer.put(1.2F);         ... Read More

Advertisements