Java Articles

Page 41 of 450

ConcurrentLinkedDeque in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 117 Views

The ConcurrentLinkedDeque Class in Java implements a deque and used a concurrent linked list for help. This class implements the Collection interface as well as the AbstractCollection class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.*; public class Demo {    public static void main(String[] args) {       ConcurrentLinkedDeque clDeque = new ConcurrentLinkedDeque();       clDeque.add("James");       clDeque.add("May");       clDeque.add("John");       clDeque.add("Sara");       clDeque.add("Anne");       System.out.println("The elements in ConcurrentLinkedDeque are: " + clDeque);    } }The ...

Read More

LinkedBlockingDeque in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 397 Views

The LinkedBlockingDeque Class in Java has a blockingdeque that is optionally bounded and based on linked nodes. This class implements the Collection interface as well as the AbstractQueue class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.LinkedBlockingDeque; public class Demo {    public static void main(String[] args) {       LinkedBlockingDeque lbDeque = new LinkedBlockingDeque();       lbDeque.add("James");       lbDeque.add("May");       lbDeque.add("John");       lbDeque.add("Sara");       lbDeque.add("Anne");       System.out.println("Size of LinkedBlockingDeque is: " + lbDeque.size());       ...

Read More

ConcurrentSkipListSet in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 319 Views

The ConcurrentSkipListSet has elements that are sorted by default. Also, its implementation is based on the ConcurrentSkipListMap. The ConcurrentSkipListSet class also implements the Collection interface as well as the AbstractSet class. It is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.ConcurrentSkipListSet; public class Demo {    public static void main(String[] args) {       ConcurrentSkipListSet csls = new ConcurrentSkipListSet();       csls.add(7);       csls.add(4);       csls.add(1);       csls.add(9);       csls.add(3);       System.out.println("The elements in ConcurrentSkipListSet are: " + csls); ...

Read More

DoubleBuffer arrayOffset() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 119 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.DoubleBuffer. If the buffer backed by the array is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          DoubleBuffer buffer = DoubleBuffer.allocate(5);          buffer.put(4.5D);          buffer.put(1.2D);          buffer.put(3.9D);          buffer.put(7.5D); ...

Read More

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

Samual Sam
Samual Sam
Updated on 11-Mar-2026 6K+ 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 −Exampleimport 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

ShortBuffer order() Method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 132 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 −Exampleimport 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

ByteBuffer asShortBuffer() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 224 Views

A view of the ByteBuffer can be created as a ShortBuffer using the asShortBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a short 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 −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 50;       try {          ByteBuffer bufferB = ByteBuffer.allocate(n);          ShortBuffer bufferS = bufferB.asShortBuffer();         ...

Read More

ByteBuffer compact() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 321 Views

The buffer can be compacted using the compact() method in the class java.nio.ByteBuffer. This method does not require a parameter and it returns the new compacted ByteBuffer 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 −Exampleimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { ByteBuffer buffer = ...

Read More

ByteBuffer duplicate() method in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 471 Views

A duplicate buffer of a buffer can be created using the method duplicate() in the class java.nio.ByteBuffer. 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 −Exampleimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ByteBuffer buffer1 = ByteBuffer.allocate(5);          buffer1.put((byte)1);          buffer1.put((byte)2);          buffer1.put((byte)3);          buffer1.put((byte)4);   ...

Read More

ByteBuffer get() method in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 533 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.ByteBuffer. 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 −Exampleimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { ByteBuffer buffer = ByteBuffer.allocate(n); ...

Read More
Showing 401–410 of 4,496 articles
« Prev 1 39 40 41 42 43 450 Next »
Advertisements