Nancy Den has Published 335 Articles

LongStream mapToDouble() method in Java

Nancy Den

Nancy Den

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

94 Views

The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows:DoubleStream mapToDouble(LongToDoubleFunction mapper)The parameter mapper is a stateless function to apply to each element.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;The following ... Read More

Create Decade Tuple from an array in Java

Nancy Den

Nancy Den

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

61 Views

To create Decade Tuple from array in Java, use the fromArray() method. Here, we will see how to create a Decade Tuple using the fromArray() method. Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following ... Read More

LongStream generate() method in Java

Nancy Den

Nancy Den

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

77 Views

The generate() method of the LongStream class returns an infinite sequential unordered stream where each element is generated by the provided LongSupplier.The syntax is as follows:static LongStream generate(LongSupplier s)Here, s is the LongSupplier for generate elements. The LongSupplier is the supplier of long-valued results.To use the LongStream class in Java, ... Read More

Create KeyValue Tuple using with() method in Java

Nancy Den

Nancy Den

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

62 Views

To create a KeyValue tuple in Java, you can use the with() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package:import org.javatuples.KeyValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are ... Read More

IntStream builder() method in Java

Nancy Den

Nancy Den

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

65 Views

The builder() method in IntStream class is used to return a builder for an IntStream.The syntax is as follows:static IntStream.Builder builder()Here, we have created an IntStream and used the builder() method. An element is added using add() method:IntStream intStream = IntStream.builder().add(25).build();The following is an example to implement IntStream builder() method ... Read More

Instant hashCode() method in Java

Nancy Den

Nancy Den

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

119 Views

The hash code for a particular Instant object can be obtained using the hashCode() method in the Instant class in Java. This method requires no parameters and it returns the hash code for the Instant object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class ... Read More

Generate Infinite Stream of Integers in Java using IntStream.generate()

Nancy Den

Nancy Den

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

108 Views

You can also generate Infinite Stream of Integers in Java with IntStream.generate() method. Here, we have used the Random class to get the list of random integers:Random r = new Random();After that use IntStream.generate() and the nextInt() method gets the next random integer:IntStream.generate(r::nextInt)The following is an example displaying how to ... Read More

Instant equals() method in Java

Nancy Den

Nancy Den

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

740 Views

The equality of two Instant objects can be determined using the equals() method in the Instant class in Java. This method requires a single parameter i.e. the Instant to be compared. Also it returns true if both the Instant objects are equal and false otherwise.A program that demonstrates this is ... Read More

Instant compareTo() method in Java

Nancy Den

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 ... Read More

Instant atZone() method in Java

Nancy Den

Nancy Den

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

85 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 ... Read More

Advertisements