Found 9150 Articles for Object Oriented Programming

ByteBuffer arrayOffset() method in Java

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

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

ShortBuffer hasArray() method in Java

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

108 Views

It can be checked if a buffer has the backing of an accessible short array by using the method hasArray() in the class java.nio.ShortBuffer. This method returns true if the buffer has the backing of an accessible double 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 { ShortBuffer buffer = ShortBuffer.allocate(5); ... Read More

ShortBuffer compareTo() method in Java

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

109 Views

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

ShortBuffer duplicate() method in Java

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

99 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.ShortBuffer. 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 {          ShortBuffer buffer1 = ShortBuffer.allocate(5);          buffer1.put((short)12);          buffer1.put((short)91);          buffer1.put((short)25);          buffer1.put((short)18); ... Read More

ShortBuffer asReadOnlyBuffer() method in Java

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

106 Views

A read-only short buffer can be created using the contents of a buffer with the method asReadOnlyBuffer() in the class java.nio.ShortBuffer. 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 {          ShortBuffer buffer = ShortBuffer.allocate(5);          buffer.put((short)12); ... Read More

ShortBuffer arrayOffset() method in Java

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

120 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.ShortBuffer. 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 {          ShortBuffer buffer = ShortBuffer.allocate(5);          buffer.put((short)12);          buffer.put((short)91);          buffer.put((short)25);         ... Read More

ShortBuffer array() Method in Java

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

168 Views

A short array for the buffer can be obtained using the method array() in the class java.nio.ShortBuffer. 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 {          ShortBuffer buffer = ShortBuffer.allocate(n);          buffer.put((short)12);          buffer.put((short)91); ... Read More

ShortBuffer compact() method in Java

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

113 Views

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

ShortBuffer allocate() method in Java

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

127 Views

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

ShortBuffer slice() method in Java

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

133 Views

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

Advertisements