![]() |
VOOZH | about |
ByteBuffer holds a sequence of integer values to be used in an I/O operation. The ByteBuffer class provides the following four categories of operations upon long buffers:
Short buffers can be created by:
Most of the methods of ByteBuffer class are directly analogous to the methods defined by ByteBuffer.
Class Declaration:
public abstract class ByteBuffer
extends Buffer
implements Comparable<ByteBuffer>
Methods of CharBuffer class:
| Method | Description |
|---|---|
| allocate(int capacity) | This method allocates a new byte buffer. |
| allocateDirect(int capacity) | This method allocates a new direct byte buffer. |
| array() | This method returns the byte array that backs this buffer |
| arrayOffset() | This method returns the offset within this buffer's backing array of the first element of the buffer. |
| asCharBuffer() | This method creates a view of this byte buffer as a char buffer. |
| asDoubleBuffer() | This method creates a view of this byte buffer as a double buffer. |
| asFloatBuffer() | This method creates a view of this byte buffer as a float buffer. |
| asIntBuffer() | This method creates a view of this byte buffer as an int buffer. |
| asLongBuffer() | This method creates a view of this byte buffer as a long buffer. |
| asReadOnlyBuffer() | This method creates a new, read-only byte buffer that shares this buffer's content. |
| asShortBuffer() | This method creates a view of this byte buffer as a short buffer. |
| compact() | This method compacts this buffer. |
| compareTo(ByteBuffer that) | This method compares this buffer to another. |
| duplicate() | This method creates a new byte buffer that shares this buffer's content. |
| equals(Object ob) | This method tells whether this buffer is equal to another object. |
| get() | This method is a relative get method and returns the byte at the buffer's current position. |
| get(byte[] dst) | This method is a relative bulk get method and returns this buffer. |
| get(byte[] dst, int offset, int length) | This method is a Relative bulk get method and returns this buffer. |
| get(int index) | This method is an Absolute get method and returns the byte at the given index. |
| getChar() | This method is a Relative get method for reading a char value and returns the char value at the buffer's current position. |
| getChar(int index) | This method is an Absolute get method for reading a char value and returns the char value at the given index. |
| getDouble() | This method is a Relative get method for reading a double value and returns the double value at the buffer's current position. |
| getDouble(int index) | This method is an Absolute get method for reading a double value and returns the double value at the given index. |
| getFloat() | This method is a Relative get method for reading a float value and returns the float value at the buffer's current position. |
| getFloat(int index) | This method is an Absolute get method for reading a float value and returns the float value at the given index. |
| getInt() | This method is a Relative get method for reading an int value and returns the int value at the buffer's current position. |
| getInt(int index) | This method is an Absolute get method for reading an int value and returns the int value at the given index. |
| getLong() | This method is a Relative get method for reading a long value and returns the long value at the buffer's current position. |
| getLong(int index) | This method is an Absolute get method for reading a long value and returns the int value at the given index. |
| getShort() | This method is a Relative get method for reading a short value and returns the long value at the buffer's current position. |
| getShort(int index) | This method is an Absolute get method for reading a short value and returns the int value at the given index. |
| hasArray() | This method tells whether this buffer is backed by an accessible byte array. |
| hashCode() | This method returns the current hash code of this buffer. |
| isDirect() | This method tells whether this byte buffer is direct. |
| order() | This method retrieves this buffer's byte order. |
| order(ByteOrder bo) | This method modifies this buffer's byte order. |
| put(byte b) | This method is a Relative put method and returns this buffer. |
| put(byte[] src) | This method is a Relative bulk put method and returns this buffer. |
| put(ByteBuffer src) | This method is a Relative bulk put method and returns this buffer. |
| put(int index, byte b) | This method is an Absolute put method and returns this buffer. |
| putChar(char value) | This method is a Relative put method for writing a char value . |
| putChar(int index, char value) | This method is an absolute put method for writing a char value. |
| putDouble(double value) | This method is a relative put method for writing a double value. |
| putDouble(int index, double value) | This method is an absolute put method for writing a double value. |
| putFloat(float value) | This method is a relative put method for writing a float value. |
| putFloat(int index, float value) | This method is an absolute put method for writing a float value. |
| putInt(int value) | This method is a relative put method for writing an int value. |
| putInt(int index, int value) | This method is an absolute put method for writing an int value. |
| putLong(int index, long value) | This method is an absolute put method for writing a long value. |
| putLong(long value) | This method is a relative put method for writing a long value. |
| putShort(int index, short value) | This method is an absolute put method for writing a short value. |
| putShort(short value) | This method is a relative put method for writing a short value. |
| slice() | This method creates a new byte buffer whose content is a shared subsequence of this buffer's content. |
| toString() | This method returns a string summarizing the state of this buffer. |
| wrap(byte[] array) | This method wraps a byte array into a buffer. |
| wrap(byte[] array, int offset, int length) | This method wraps a byte array into a buffer. |
Following are some programs to demonstrate CharBuffer class and its methods:
Example 1:
Original ByteBuffer: [10, 20, 30, 40]
Example 2:
Char buffer : G e e k s F o r G e e k s