Found 34489 Articles for Programming

FloatBuffer wrap() method in Java

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

89 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

129 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

81 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

74 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

FloatBuffer arrayOffset() method in Java

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

59 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.FloatBuffer. 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 {          FloatBuffer buffer = FloatBuffer.allocate(5);          buffer.put(4.5F);          buffer.put(1.2F);          buffer.put(3.9F);         ... Read More

FloatBuffer compact() method in Java

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

66 Views

The buffer can be compacted using the compact() method in the class java.nio.FloatBuffer. This method does not require a parameter and it returns the new compacted FloatBuffer 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 {          FloatBuffer buffer = FloatBuffer.allocate(n);          buffer.put(1.2F);          buffer.put(3.9F);   ... Read More

FloatBuffer allocate() method in Java

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

83 Views

A new FloatBuffer can be allocated using the method allocate() in the class java.nio.FloatBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new FloatBuffer 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 {          FloatBuffer buffer = FloatBuffer.allocate(n);          buffer.put(4.5F);          buffer.put(1.2F);   ... Read More

FloatBuffer compareTo() method in Java

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

91 Views

A buffer can be compared with another buffer using the method compareTo() in the class java.nio.FloatBuffer. This method returns a negative integer if the buffer is less than the given buffer, zero if the buffer is equal to the given buffer and a positive integer if the buffer is greater than the given 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 buffer1 = FloatBuffer.allocate(n);     ... Read More

IntBuffer equals() method in Java

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

126 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.IntBuffer. 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 {          IntBuffer buffer1 = IntBuffer.allocate(n);          buffer1.put(8); ... Read More

IntBuffer arrayOffset() method in Java

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

61 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.IntBuffer. 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 {          IntBuffer buffer = IntBuffer.allocate(5);          buffer.put(8);          buffer.put(1);          buffer.put(3);         ... Read More

Advertisements