Found 9326 Articles for Object Oriented Programming

ConcurrentSkipListSet in Java

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

162 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 −Example Live Demoimport 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: " + ... Read More

LinkedBlockingDeque in Java

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

244 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 −Example Live Demoimport 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

ConcurrentLinkedDeque in Java

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

44 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 −Example Live Demoimport 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);    } ... Read More

PriorityBlockingQueue Class in Java

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

71 Views

The PriorityBlockingQueue Class in Java has a blocking queue that has unbounded functionality and is based on the class PriorityQueue with the same ordering rules. The PriorityBlockingQueue Class is a part of the Java Collection Framework.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.PriorityBlockingQueue; public class Demo {    public static void main(String[] args) {       PriorityBlockingQueue pbQueue = new PriorityBlockingQueue();       pbQueue.add("James");       pbQueue.add("May");       pbQueue.add("John");       pbQueue.add("Sara");       pbQueue.add("Anne");       System.out.println("The elements in PriorityBlockingQueue are: " + pbQueue);    } }The ... Read More

LinkedTransferQueue in Java

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

39 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 −Example Live Demoimport 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

LinkedBlockingQueue Class in Java

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

99 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 −Example Live Demoimport 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

ConcurrentLinkedQueue in Java

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

95 Views

The ConcurrentLinkedQueue class in Java is used to implement a queue using a concurrent linked list. 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 −Example Live Demoimport java.util.concurrent.*; public class Demo {    public static void main(String[] args) {       ConcurrentLinkedQueue clQueue = new ConcurrentLinkedQueue();       clQueue.add("Amy");       clQueue.add("John");       clQueue.add("May");       clQueue.add("Harry");       clQueue.add("Anne");       System.out.println("The elements in ConcurrentLinkedQueue are: " + clQueue);    } ... Read More

ArrayBlockingQueue Class in Java

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

96 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 −Example Live Demoimport 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

Difference between Synchronized ArrayList and CopyOnWriteArrayList in Java

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

886 Views

Synchronized ArrayList and CopyOnWriteArrayList are useful for synchronizing the ArrayList. This is necessary for a multi-threaded environment to make sure thread safety is achieved.The differences between Synchronized ArrayList and CopyOnWriteArrayList are given as follows −Synchronized ArrayListCopyOnWriteArrayListSynchronized ArrayList is used to synchronize the ArrayList.CopyOnWriteArrayList is used to synchronize the ArrayList.The Java 1.2 version first introduced the Synchronized ArrayList.The Java 1.5 version first introduced the CopyOnWriteArrayList.The Synchronized ArrayList should be used when there are more write operations than reading operations in ArrayList.The CopyOnWriteArrayList should be used when there are more read operations than write operations in ArrayList.This iterator is a fail-fast iterator.This ... Read More

Custom ArrayList in Java

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

710 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 −Example Live Demoimport 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, ... Read More

Advertisements