Found 7442 Articles for Java

ArrayBlockingQueue poll() Method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

189 Views

The poll() method of the ArrayBlockingQueue class in Java retrieves and removes the head of this queue, or returns null if this queue is empty.The syntax is as follows:E poll()To work with ArrayBlockingQueue class, you need to import the following package:import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement poll() method of Java ArrayBlockingQueue class:Example Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(200);       q.add(310);         q.add(400);       q.add(450);       q.add(500);     ... Read More

DoubleStream empty() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

71 Views

The empty() method of the DoubleStream class in Java returns an empty sequential DoubleStream.The syntax is as follows:static DoubleStream empty()To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Let us create an empty DoubleStream:DoubleStream doubleStream = DoubleStream.empty();Now, let us check the number of elements in the stream. It will be 0, since the stream is set to empty:doubleStream.count()The following is an example to implement DoubleStream empty() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.empty();       System.out.println("Number of elements in the stream ... Read More

DoubleStream toArray() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

129 Views

The toArray() method returns an array containing the elements of this stream.The syntax is as follows:double[] toArray()To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create DoubleStream and add some elements:DoubleStream doubleStream = DoubleStream.of(20.7, 30.5, 45.9, 60.2, 75.9, 88.3, 95.2);Now, use the toArray() method to return an array with the stream elements:double[] myArr = doubleStream.toArray();The following is an example to implement DoubleStream toArray() method in Java:Example Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.of(20.7, 30.5, 45.9, 60.2, 75.9, 88.3, 95.2);       double[] ... Read More

LongStream findAny() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

119 Views

The findAny() method of the LongStream class in Java returns an OptionalLong describing some element of the stream, or an empty OptionalLong if the stream is empty.The syntax is as follows:OptionalLong findAny()Here, OptionalLong is a container object which may or may not contain a long value.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;The following is an example to implement LongStream findAny() method. The isPresent() method of the OptionalLong class returns true if the value is present:Exampleimport java.util.OptionalLong; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = ... Read More

Create Ennead Tuple using with() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

141 Views

To create Ennead Tuple, you can use the with() method. With that, you can also add elements to it. Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following package:import org.javatuples.Ennead;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is ... Read More

ArrayBlockingQueue toArray() Method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

101 Views

The toArray() method of the ArrayBlockingQueue class returns an array containing all of the elements in this queue.The syntax is as follows:Object[] toArray()To work with ArrayBlockingQueue class, you need to import the following package:import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement toArray() method of Java ArrayBlockingQueue class:Example Live Demoimport java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(200);       q.add(310);       q.add(400);       q.add(450);       q.add(500);       q.add(550);       q.add(700); ... Read More

The addAll() method of Java AbstractSequentialList class

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

130 Views

The addAll() method of the AbstractSequentialList class inserts all the elements in the specified collection into this list at the specified position. Set the specified position as the parameter.The syntax is as follows:boolean addAll(int index, Collection

The size() method of Java AbstractCollection class

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

189 Views

The size() method of the AbstractCollection class returns the numbers of elements in the collection. The method returns Integer.MAX_VALUE if the total number of elemnts in the collection exceeds the Interger.MAX_VALUE.The syntax is as follows:public abstract int size()To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection size() method in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Laptop");       absCollection.add("Tablet");       absCollection.add("Mobile");       absCollection.add("E-Book Reader"); ... Read More

StringJoiner length() method in Java 8

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

245 Views

The length() method of the StringJoiner class in Java 8 is used to get the length of the current value of StringJoiner.To work with the StringJoiner in Java 8, import the following package:import java.util.StringJoiner;The syntax is as follows:public int length()First, create a StringJoiner:StringJoiner strJoin = new StringJoiner(", "); strJoin.add("US"); strJoin.add("India"); strJoin.add("Netherlands"); strJoin.add("Australia");Now, find the length of the StringJoiner i.e. the number of elements in it using the length() method:strJoin.length());The following is an example to implement StringJoiner length() method in Java:Example Live Demoimport java.util.StringJoiner; public class Demo {    public static void main(String[] args) {       // StringJoiner     ... Read More

What is Octet class in JavaTuples?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

159 Views

An Octetclass is a Tuple of 8 element. It is in the JavaTuples library. The following is the declaration of the Octet class:public final class Octet extends Tuple implements IValue0, IValue1, IValue2, IValue3, IValue4, IValue5, IValue6, IValue7Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package:import org.javatuples.Octet;Some of its features include:TypesafeSerializableComparableIterableImmutableNote: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar ... Read More

Advertisements