Found 9326 Articles for Object Oriented Programming

ShortBuffer arrayOffset() method in Java

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

75 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

99 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

77 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

76 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

75 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

ShortBuffer toString() method in Java

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

94 Views

A string that provides the buffer state in a summary can be obtained using the method toString() in the class java.nio.ShortBuffer. This method requires no parameters and it returns the buffer state in a summary using a string.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);          buffer.put((short)25);       ... Read More

ShortBuffer order() Method in Java

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

64 Views

The byte order of the buffer can be obtained using the method order() in the class java.nio.ShortBuffer. This method requires no parameters and it returns the byte order of the 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(n);          buffer.put((short)12);          buffer.put((short)91);          buffer.put((short)25);          buffer.put((short)18);          buffer.put((short)30); ... Read More

ShortBuffer equals() method in Java

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

78 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.ShortBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and 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 {          ShortBuffer buffer1 = ShortBuffer.allocate(n);          buffer1.put((short)12); ... Read More

Fix for java.math.BigInteger cannot be cast to java.lang.Integer?

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

5K+ Views

You can typecast with the help of method intValue(). The syntax is as follows −Integer yourVariableName=((BigInteger) yourBigIntegerValue).intValue();Here is the Java code to convert java.math.BigInteger cast to java.lang.Integer. The code is as follows −Example Live Demoimport java.math.BigInteger; public class BigIntegerToInteger {    public static void main(String []args) {       BigInteger bigValue [] = new BigInteger[5];       bigValue[0] = new BigInteger("6464764");       bigValue[1] = new BigInteger("212112221122");       bigValue[2] = new BigInteger("76475");       bigValue[3] = new BigInteger("94874747");       bigValue[4] = new BigInteger("2635474");       for(int i = 0; i< bigValue.length; i++) ... Read More

DoubleBuffer array() method in Java

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

74 Views

A double array for the buffer can be obtained using the method array() in the class java.nio.DoubleBuffer. 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 {          DoubleBuffer buffer = DoubleBuffer.allocate(n);          buffer.put(4.5D);          buffer.put(1.2D); ... Read More

Advertisements