Java Articles

Page 45 of 450

ByteBuffer asLongBuffer() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 140 Views

A view of the ByteBuffer can be created as a LongBuffer using the asLongBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a long buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          LongBuffer bufferL = bufferB.asLongBuffer();         ...

Read More

ByteBuffer asReadOnlyBuffer() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 566 Views

A read-only byte buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.ByteBuffer. 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 −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {     int n = 5;     try {       ByteBuffer buffer = ByteBuffer.allocate(5);     ...

Read More

ByteBuffer asDoubleBuffer() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 180 Views

A view of the ByteBuffer can be created as a DoubleBuffer using the asDoubleBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a double buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          DoubleBuffer bufferD = bufferB.asDoubleBuffer();         ...

Read More

ByteBuffer allocateDirect() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 383 Views

A direct byte buffer can be allocated using the method allocateDirect() in the class java.nio.ByteBuffer. This method requires a single parameter i.e. the capacity in bytes and it returns the direct byte buffer. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ByteBuffer buffer = ByteBuffer.allocateDirect(n);          byte[] byteValues = { 7, 1, 6, 3, 8 ...

Read More

ByteBuffer asCharBuffer() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 177 Views

A view of the ByteBuffer can be created as a CharBuffer using the asCharBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a char buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {     ByteBuffer bufferB = ByteBuffer.allocate(n); ...

Read More

ByteBuffer allocate() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 468 Views

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

Read More

ByteBuffer asFloatBuffer() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 205 Views

A view of the ByteBuffer can be created as a FloatBuffer using the asFloatBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a float buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          FloatBuffer bufferF = bufferB.asFloatBuffer();         ...

Read More

ByteBuffer asIntBuffer() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 145 Views

A view of the ByteBuffer can be created as an IntBuffer using the asIntBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns an int buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          IntBuffer bufferI = bufferB.asIntBuffer();         ...

Read More

CharBuffer put() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 160 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.CharBuffer. 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 −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          CharBuffer buffer = CharBuffer.allocate(5);       ...

Read More

CharBuffer hasArray() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 164 Views

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

Read More
Showing 441–450 of 4,498 articles
« Prev 1 43 44 45 46 47 450 Next »
Advertisements