Object Oriented Programming Articles

Page 229 of 589

Custom ArrayList in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

A custom ArrayList can have multiple types of data and its attributes in general are based on the user requirements.A program that demonstrates a custom ArrayList is given as follows −Exampleimport java.util.ArrayList; public class CustomArrayList {    int n = 5;    class Employee {       int eno;       String name;       Employee(int eno, String name) {          this.eno = eno;          this.name = name;       }    }    public static void main(String args[]) {       int eno[] = {101, 102, 103, 104, ...

Read More

ArrayBlockingQueue Class in Java

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

A bounded blocking queue that is backed by an array is known as a ArrayBlockingQueue Class in Java. The size of the queue is fixed in the class and it uses FIFO for ordering elements. The ArrayBlockingQueue Class is a member of the Java Collections Framework.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) {       int n = 10;       ArrayBlockingQueue abQueue = new ArrayBlockingQueue(n);       abQueue.add(7);       abQueue.add(2);       abQueue.add(6);       abQueue.add(3);     ...

Read More

LinkedBlockingQueue Class in Java

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

The LinkedBlockingQueue Class in Java has a blocking queue that is optionally bounded and based on linked nodes. This means that if the capacity is provided then the LinkedBlockingQueue is bound, otherwise it is not bound. Also, FIFO for ordering elements.A program that demonstrates this is given as follows −Exampleimport java.util.concurrent.LinkedBlockingQueue; public class Demo {    public static void main(String[] args) {       LinkedBlockingQueue lbQueue = new LinkedBlockingQueue();       lbQueue.add("Amy");       lbQueue.add("John");       lbQueue.add("May");       lbQueue.add("Harry");       lbQueue.add("Anne");       System.out.println("The elements in LinkedBlockingQueue are: " + ...

Read More

LinkedTransferQueue in Java

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

The LinkedTransferQueue Class in Java has a transfer queue that has unbounded functionality and is based on linked nodes. It uses FIFO for ordering elements. 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.LinkedTransferQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       LinkedTransferQueue ltQueue = new LinkedTransferQueue();       ltQueue.add("Amy");       ltQueue.add("John");       ltQueue.add("May");       ltQueue.add("Harry");       ltQueue.add("Anne");       ...

Read More

ConcurrentLinkedDeque in Java

Samual Sam
Samual Sam
Updated on 11-Mar-2026 129 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 410 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 327 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 130 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 141 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
Showing 2281–2290 of 5,881 articles
« Prev 1 227 228 229 230 231 589 Next »
Advertisements