Found 4332 Articles for Java 8

LocalTime equals() method in Java

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

313 Views

The equality of two LocalTime objects can be determined using the equals() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object to be compared. Also it returns true if both the LocalTime objects are equal and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalTime lt1 = LocalTime.parse("23:15:30");       LocalTime lt2 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime lt1 is: " + lt1);       System.out.println("The LocalTime lt2 is: " + ... Read More

IntStream sorted() method in Java

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

237 Views

The sorted() method in Java IntStream class is used to return a stream consisting of the elements of this stream in sorted order.The syntax is as followsIntStream sorted()The sorted() method returns the new stream. To work with the IntStream class, you need to import the following packageimport java.util.stream.IntStream;Create an IntStream and add some elementsIntStream intStream = IntStream.of(30, 50, 70, 120, 150, 200, 250, 300);Now, to sort the above stream elements, use the sorted() methodintStream.sorted() The following is an example to implement IntStream sorted() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) { ... Read More

LocalTime ofSecondOfDay() method in Java

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

73 Views

A LocalTime object can be obtained using the seconds of the day with the ofSecondOfDay() method in the LocalTime class in Java. This method requires a single parameter i.e. the seconds of the day and it returns the LocalTime object for the seconds of the day.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       long seconds = 18930;       System.out.println("The seconds of the day: " + seconds);       System.out.println("The LocalTime is: " + LocalTime.ofSecondOfDay(seconds));    } }outputThe seconds of the ... Read More

IntStream rangeClosed() method in Java

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

929 Views

The rangeClosed() class in the IntStream class returns a sequential ordered IntStream from startInclusive to endInclusive by an incremental step of 1. This includes both the startInclusive and endInclusive values.The syntax is as followsstatic IntStream rangeClosed(int startInclusive, int endInclusive)Here, startInclusive is the value including the first value and endInclusive is the value indicating the last value. To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;The following is an example to implement IntStream rangeClosed() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) { ... Read More

DoubleStream mapToLong() method in Java

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

90 Views

The mapToLong() method of the DoubleStream class returns a LongStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsLongStream mapToLong(DoubleToLongFunction mapper)Here, the parameter mapper is a stateless function to apply to each element. The DoubleToLongFunction here is a function that accepts a double-valued argument and produces a long-valued result.To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;Create a DoubleStream and add some elementsDoubleStream doubleStream = DoubleStream.of(30.5, 45.8, 89.3);Now, use the LongStream and set a condition for the stream elementsLongStream longStream = doubleStream.mapToLong(a -> (long)a); The following is ... Read More

LocalTime hashCode() method in Java

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

92 Views

The hash code value of the LocalTime can be obtained using the hashCode() method in the LocalTime class in Java. This method requires no parameters and it returns the hash code value of the LocalTime.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 hash code is: " + lt.hashCode());    } }outputThe LocalTime is: 23:15:30 The hash code is: -387418074Now let us understand the above program.First the LocalTime is displayed. ... Read More

DoubleStream boxed() method in Java

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

123 Views

The boxed() method of the DoubleStream class returns a Stream consisting of the elements of this stream, boxed to Double.The syntax is as followsStream boxed()Here, Double is the class that wraps a value of the primitive type double in an object. To work with DoubleStream class in Java, import the following pageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream boxed() method in JavaExample Live Demoimport java.util.*; import java.util.stream.Stream; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(80.2, 84.6, 88.9, 92.9); ... Read More

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

Advertisements