How to Read a 2d Array in Java

Today we are going to learn how to read a 2d array in Java. To construct a two-dimensional array, we want the number of rows, columns, and its elements. Finally, we display all the user input in a matrix format. Program to read a 2d array in java Let’s have Read more…

Declare and Initialize 2d Array in Java

In this post, we are going to look at how to declare and initialize the 2d array in Java. Each element in the primitive two-dimensional array gets their respective default values, whereas object array gets null value. Program to Declare 2d Array In the below program, we will look at Read more…

Java ArrayBlockingQueue clear() Method

The clear() method of ArrayBlockingQueue removes all the elements from the queue. The queue becomes empty after calling this method. Syntax: Program to show ArrayBlockingQueue clear() method Let’s have a look at the program. Output: Example: The below example shows how clear() method removes all the user-defined objects from the Read more…

Java ArrayBlockingQueue remainingCapacity() Method

The remainingCapacity() method of ArrayBlockingQueue returns the remaining capacity of the queue. It returns an integer value. For example, if the queue capacity is ten, and the queue contains six elements, then the remainingCapacity() method returns four. Syntax: Program to show ArrayBlockingQueue remainingCapacity() Let’s have a look at the program. Read more…

Java ArrayBlockingQueue contains() Method

The contains() method in ArrayBlockingQueue checks if the queue has the specified element. If the element is available in the queue, then it returns true. Otherwise, it returns false. Syntax: Parameter – e is the element to check. Program to Demonstrate ArrayBlockingQueue contains() Method Let’s have a look at the Read more…

Java ArrayBlockingQueue peek() Method

The peek() method of ArrayBlockingQueue returns the head element of the queue. It retrieves but does not remove the element. It returns null if the queue is empty. Syntax: Program to Retrieve Element using the Peek Method Let’s have a look at how to use the peek() method to retrieve Read more…

Java ArrayBlockingQueue offer() Method

The offer() method in ArrayBlockingQueue appends the specified element at the end of the queue if the queue is not full. It can wait until the specified waiting time for space to get free and then inserts the element. It returns true on successful insertion otherwise returns false. The method Read more…