Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Page 229 of 589
Custom ArrayList in Java
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 MoreArrayBlockingQueue Class in Java
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 MoreLinkedBlockingQueue Class in Java
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 MoreLinkedTransferQueue in Java
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 MoreConcurrentLinkedDeque in Java
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 MoreLinkedBlockingDeque in Java
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 MoreConcurrentSkipListSet in Java
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 MoreDoubleBuffer arrayOffset() method in Java
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 MoreFix for java.math.BigInteger cannot be cast to java.lang.Integer?
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 MoreShortBuffer order() Method in Java
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