Programming Articles - Page 2855 of 3368

PriorityBlockingQueue Class in Java

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

150 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

73 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

172 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

171 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

180 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

1K+ 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

985 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

AbstractSequentialList in Java

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

139 Views

The Java Collection Framework contains the AbstractSequentialList class. This class is used to create and implement an unmodifiable list. Also this class implements the Collection interface and the AbstractCollection class.A program that demonstrates this is given as follows −Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       AbstractSequentialList list = new LinkedList();       list.add("John");       list.add("Martha");       list.add("Sally");       list.add("Susan");       list.add("Harry");       System.out.println("The elements are: " + list);    } }The output of the above program is as follows ... Read More

Java Program to read the next byte of data from the input stream

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

446 Views

The method java.io.InputStream.read() is used to read the next byte of data from the input stream. This method requires no parameters and it returns the next data byte in the form of int. If the stream end is reached, it returns -1.A program that demonstrates this is given as follows −Exampleimport java.io.InputStream; public class Demo {    public static void main(String[] args) throws Exception {       InputStream input = null;       int i;       char c;       try {          input = new FileInputStream("C://JavaProgram//data.txt");          System.out.println("The ... Read More

Java Program to mark the current position in this input stream

Alshifa Hasnain
Updated on 30-Dec-2024 19:14:42

524 Views

In this article, we will learn to mark and reset the current position in a file input stream in Java. Marking the current position in an input stream is a crucial functionality provided by Java’s InputStream class. It enables developers to reset the stream to a previously marked position, facilitating efficient data handling, especially in scenarios like re-reading or backtracking within a file. Key Concepts Following are the key concepts we need to know to mark the current position in this input stream − InputStream Class: The InputStream class is an abstract class that represents ... Read More

Advertisements