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…

Java ArrayBlockingQueue put() Method

The put() method of ArrayBlockingQueue class appends the specified element at the tail of the queue if the queue is not full. If the queue is full, then it waits for space to become available. It throws below exceptions: InterruptedException – if interrupted while waiting. NullPointerException – if the specified Read more…

Java ArrayBlockingQueue add() Method

The add() method of ArrayBlockingQueue appends the specified element at the end of the queue. It returns true on the successful insertion of the element. It can throw below exceptions: IllegalStateException – if the queue is full. NullPointerException – if the specified element is null. Syntax: where e is the Read more…

Convert String to int in Java

In this article, we will look at the ways to convert String to int in Java using Integer.parseInt() and Integer.valueOf() methods. One of the main reason for conversion is that we can easily perform mathematical operations on the int data type. Convert String to int using Integer.parseInt() If you want Read more…

Functional Interface in Java

A functional interface in java has only one abstract method, and it can have any number of default and static methods. It makes it easier to write lambda expressions. The Displayable user-defined interface has one and only one abstract method, so it is a functional interface.   Code with an Read more…