Found 4332 Articles for Java 8

ArrayBlockingQueue peek() Method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

91 Views

The peek() method of the ArrayBlockingQueue class returns the head of this queue or null if this queue is empty.The syntax is as follows.public E peek()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement peek() 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);       q.add(550);       ... Read More

Period plusDays() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

122 Views

An immutable copy of the Period object where some days are added to it can be obtained using the plusDays() method in the Period class in Java. This method requires a single parameter i.e. the number of days to be added and it returns the Period object with the added days.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

DoubleStream allMatch() method in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:25

76 Views

The allMatch() method in the DoubleStream class returns whether all elements of this stream match the provided predicate.The syntax is as follows −boolean allMatch(DoublePredicate predicate)Here, the argument predicate is a stateless predicate to apply to elements of this stream. The DoublePredicate is a predicate of one double-valued argument.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(15.8, 28.7, 35.7, 48.1, 78.9);Now, check whether the condition is TRUE for elements of the stream −boolean res = doubleStream.allMatch(num -> num > 10); The following is an example to implement DoubleStream ... Read More

LongStream allMatch() in Java

George John
Updated on 30-Jul-2019 22:30:25

43 Views

The allMatch() method in the LongStream class returns whether all elements of this stream match the provided predicate.The syntax is as follows.boolean allMatch(LongPredicate predicate)The parameter predicate is a stateless predicate to apply to elements of this stream. The LongPredicate represents a predicate of one long-valued argument.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream allMatch() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(100L, 150L, 200L, 300L, 400L, 500L);       boolean res = longStream.allMatch(a ... Read More

Instant atZone() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

91 Views

An Instant can be combined with a timezone to create a ZonedDateTime object using the atZone() method in the Instant class in Java. This method requires a single parameter i.e. the ZoneID and it returns the ZonedDateTime object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Instant i = Instant.parse("2019-01-13T18:35:19.00Z");       System.out.println("The Instant object is: " + i);       ZonedDateTime zdt = i.atZone(ZoneId.of("Australia/Melbourne"));       System.out.println("The ZonedDateTime object is: " + zdt);    } }OutputThe Instant object is: 2019-01-13T18:35:19Z ... Read More

DoubleStream skip() method in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25

91 Views

The skip() method of the DoubleStream class in Java returns a stream consisting of the remaining elements of this stream after discarding the first numEle elements of the stream. The numEle is a parameter which you can set to skip any number of elements from the stream.The syntax is as follows −DoubleStream skip(long numEle)Here, numEle is the number of elements to skip. The leading elements are skipped.To use the DoubleStream class in Java, import the following package −import java.util.stream.DoubleStream;The following is an example to implement DoubleStream skip() method in Java −Example Live Demoimport java.util.stream.DoubleStream; public class Demo { ... Read More

LongStream anyMatch() method in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

134 Views

The anyMatch() method of the LongStream class in Java returns whether any elements of this stream match the provided predicate.The syntax is as follows.boolean anyMatch(LongPredicate predicate)Here, the parameter predicate is the stateless predicate to apply to elements of this stream. The LongPredicate represents a predicate of one long-valued argument.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream anyMatch() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(100L, 150L, 200L, 300L, 400L, 500L);       boolean ... Read More

LongStream of() method in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

104 Views

The LongStream class in Java the following two forms of the of() method.The following of() method returns a sequential LongStream containing a single element. Here is the syntaxstatic LongStream of(long t)Here, parameter t is the single element.The following of() method returns a sequential ordered stream whose elements are the specified values.static LongStream of(long… values)Here, the parameter values are the elements of the new stream.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;The following is an example to implement LongStream of() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {   ... Read More

Instant compareTo() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

2K+ Views

Two Instant objects can be compared using the compareTo() method in the Instant class in Java. This method requires a single parameter i.e. the Instant object to be compared.If the first Instant object is greater than the second Instant object it returns a positive number, if the first Instant object is lesser than the second Instant object it returns a negative number and if both the Instant objects are equal it returns zero.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Instant i1 = ... Read More

LongStream findFirst() method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

89 Views

The findFirst() method of the LongStream class in Java returns an OptionalLong describing the first element of this stream, or an empty OptionalLong if the stream is empty.The syntax is as follows.OptionalLong findFirst()Here, OptionalLong is a container object which may or may not contain a long value. For OptionalLong, import the following package.import java.util.OptionalLong;To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;Create a LongStream and add elements.LongStream longStream = LongStream.of(25000L, 35000L, 40000L, 50000L, 60000L);Now, get the first element from the stream.OptionalLong res = longStream.findFirst();The following is an example to implement LongStream findFirst() method in Java.Example Live Demoimport java.util.OptionalLong; ... Read More

Advertisements