- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34483 Articles for Programming
200 Views
A character array can be wrapped into a buffer using the method wrap() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the char 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 { ... Read More
74 Views
A buffer can be compared with another buffer using the method compareTo() in the class java.nio.CharBuffer. 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 { CharBuffer buffer1 = CharBuffer.allocate(n); buffer1.put('A'); buffer1.put('P'); ... Read More
78 Views
The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.CharBuffer. 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 { CharBuffer buffer = CharBuffer.allocate(n); buffer.put('A'); buffer.put('P'); ... Read More
64 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.CharBuffer. 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 { CharBuffer buffer = CharBuffer.allocate(5); buffer.put('A'); buffer.put('P'); buffer.put('P'); ... Read More
98 Views
A char array for the buffer can be obtained using the method array() in the class java.nio.CharBuffer. 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 { CharBuffer buffer = CharBuffer.allocate(n); buffer.put('A'); buffer.put('P'); ... Read More
70 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 −Example Live Demoimport 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'); ... Read More
56 Views
A read-only char buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.CharBuffer. 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 { CharBuffer buffer = CharBuffer.allocate(5); buffer.put('A'); ... Read More
70 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 −Example Live Demoimport 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
86 Views
The equality of two buffers can be checked using the method equals() in the class java.nio.CharBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and the 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 { CharBuffer buffer1 = CharBuffer.allocate(n); ... Read More
65 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 −Example Live Demoimport 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