Found 4336 Articles for Java 8

LocalTime getSecond() method in Java

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

96 Views

The second of minute for a particular LocalTime can be obtained using the getSecond() method in the LocalTime class in Java. This method requires no parameters and it returns the second of the minute in the range of 0 to 59.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30");       System.out.println("The LocalTime is: " + lt);       System.out.println("The second is: " + lt.getSecond());    } }outputThe LocalTime is: 23:15:30 The second is: 30Now let us understand ... Read More

Collectors averagingLong () method in Java 8

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

229 Views

The averagingLong() method of the Collectors class returns a Collector that produces the arithmetic mean of a long-valued function applied to the input elements.The syntax is as followsstatic Collector averagingLong(ToLongFunction

DoubleStream noneMatch() method in Java

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

73 Views

The noneMatch() method of the DoubleStream class returns true if none of the elements of this stream match the provided predicate.The syntax is as followsboolean noneMatch(DoublePredicate predicate)Here, predicate is a stateless predicate to apply to elements of this stream. To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create DoubleStream and add some elements to the streamDoubleStream doubleStream = DoubleStream.of(15.8, 28.7, 35.7, 48.1, 78.9);Now, TRUE is returned if none of the element match the conditionboolean res = doubleStream.noneMatch(num -> num > 90); The following is an example to implement DoubleStream noneMatch() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; ... Read More

LocalTime getNano() method in Java

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

158 Views

The nanosecond of second for a particular LocalTime can be obtained using the getNano() method in the LocalTime class in Java. This method requires no parameters and it returns the nanosecond of second in the range of 0 to 999, 999, 999.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("23:15:30.53");       System.out.println("The LocalTime is: " + lt);       System.out.println("The nanosecond is: " + lt.getNano());    } }outputThe LocalTime is: 23:15:30.530 The nanosecond is: 530000000Now let us ... Read More

DoubleStream sum() method in Java

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

136 Views

The sum() method of the DoubleStream class in Java returns the sum of elements in this stream.The syntax is as followsdouble sum()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create DoubleStream and add some elementsDoubleStream doubleStream = DoubleStream.of(23.6, 45.3, 59.6, 60.6, 73.6, 84.7, 94.8);Now, sum the elements of the streamdouble sum = doubleStream.sum(); The following is an example to implement DoubleStream sum() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(23.6, 45.3, 59.6, 60.6, 73.6, 84.7, 94.8); ... Read More

ArrayBlockingQueue drainTo() Method in Java

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

155 Views

The drainTo() method of the ArrayBlockingQueue class removes all available elements from this queue and adds them to the given collection. It returns the number of elements transferred.The syntax is as followsint drainTo(Collection

Collectors toSet() method in Java 8

Rudradev Das
Updated on 27-Dec-2023 17:51:27

2K+ Views

Collections reverse order class is a reverse order method, which is encoded in the collections class. It is present in the java.util package. It returns a comparator as a result, which is a predefined comparator in nature. By using this comparator package, we can rearrange the collections of a particular data set in a reverse manner. The Collectors toSet() is a collector class, which itself returns a collector and accumulates those particular elements as an input into a new set. toSet() is an unordered collector class which is not accountable to preserve the order of the encounter of some input ... Read More

The get() method of Java AbstractSequentialList class

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

69 Views

The get() method of the AbstractSequentialList class is used to display the element at the specified position in this list.The syntax is as followspublic E get(int index)Here, index is the location from where you want to get the element.To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList get() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList absSequential = new LinkedList(); absSequential.add(10); ... Read More

DoubleStream parallel() method in Java

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

80 Views

The parallel() method of the DoubleStream class returns an equivalent stream which is parallel.The syntax is as followsDoubleStream parallel()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream parallel() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(35.8, 14.9, 23.3, 67.8, 89.4, 45.6); System.out.println("Parallel DoubleStream = "); doubleStream.parallel().forEach(System.out::println); } }OutputParallel DoubleStream = 67.8 14.9 23.3 89.4 45.6 35.8

What is LabelValue class in JavaTuples?

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

89 Views

A LabelValue class is a Tuple of 2 elements with label as the first position, whereas value as the second. It is in the JavaTuples library. The LabelValue Tuple class is Typesafe, Immutable, Iterable, Serializable, etc.The following is the declaration of the LabelValue class;public final class LabelValue extends Tuple implements IValueLabel, IValueValueLet us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following packageimport org.javatuples.LabelValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path ... Read More

Advertisements