Found 34489 Articles for Programming

IntBuffer put() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

79 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.IntBuffer. 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 {          IntBuffer buffer = IntBuffer.allocate(5);     ... Read More

IntBuffer get() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

106 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.IntBuffer. 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 {          IntBuffer buffer = IntBuffer.allocate(n);          buffer.put(8);          buffer.put(1);       ... Read More

IntBuffer wrap() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

311 Views

An int array can be wrapped into a buffer using the method wrap() in the class java.nio.IntBuffer. 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 {          int[] arr = { 8, 1, 3, 7, 5 ... Read More

IntBuffer slice() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

96 Views

A new IntBuffer with the content as a shared subsequence of the original IntBuffer can be created using the method slice() in the class java.nio.IntBuffer. This method returns the new IntBuffer 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 {          IntBuffer buffer1 = IntBuffer.allocate(n);          buffer1.put(3);       ... Read More

IntBuffer allocate() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

166 Views

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

IntBuffer hasArray() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

83 Views

It can be checked if a buffer has the backing of an accessible int array by using the method hasArray() in the class java.nio.IntBuffer. 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 {          IntBuffer buffer = IntBuffer.allocate(5);          buffer.put(8);          buffer.put(1);         ... Read More

IntBuffer compact() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

94 Views

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

IntBuffer array() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

81 Views

An int array for the buffer can be obtained using the method array() in the class java.nio.IntBuffer. 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 {          IntBuffer buffer = IntBuffer.allocate(n);          buffer.put(8);          buffer.put(1); ... Read More

IntBuffer duplicate() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

84 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.IntBuffer. 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 {          IntBuffer buffer1 = IntBuffer.allocate(n);          buffer1.put(8);          buffer1.put(1);          buffer1.put(3);          buffer1.put(7); ... Read More

IntBuffer compareTo() method in Java

Naveen Singh
Updated on 30-Jul-2019 22:30:25

96 Views

A buffer can be compared with another buffer using the method compareTo() in the class java.nio.IntBuffer. 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 {          IntBuffer buffer1 = IntBuffer.allocate(n);     ... Read More

Advertisements