Found 34469 Articles for Programming

LongStream filter() method in Java

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

122 Views

The filter() method in the LongStream class in Java returns a stream consisting of the elements of this stream that match the given predicate.The syntax is as followsLongStream filter(LongPredicate predicate)Here, the parameter predicate is a stateless predicate to apply to each element to determine if it should be included. The LongPredicate represents a predicate (boolean-valued function) of one long-valued argumentTo use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;The following is an example to implement LongStream filter() method in JavaExample Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo {    public static void main(String[] args) { LongStream longStream = ... Read More

LocalTime from() method in Java

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

48 Views

An instance of a LocalTime object can be obtained from a Temporal object using the from() method in the LocalTime class in Java. This method requires a single parameter i.e. the Temporal object and it returns the LocalTime object that is obtained from the Temporal object.A program that demonstrates this is given as follows:import java.time.*; public class Main {    public static void main(String[] args) {       LocalTime lt = LocalTime.from(ZonedDateTime.now());       System.out.println("The LocalTime is: " + lt);    } }The output of the above program is as follows:The LocalTime is: 10:09:29.696Now let us understand the ... Read More

The addAll() method of AbstractList class in Java

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

104 Views

The addAll() method of the AbstractList class is used to insert all of the elements in the specified collection into this list at the specified position.The syntax is as followsboolean addAll(int index, Collection

LocalTime format() method in Java

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

104 Views

The LocalTime can be formatted with the specified formatter using the format() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object to be formatted and it returns the formatted LocalTime with the specified formatter.A program that demonstrates this is given as follows:Example Live Demoimport java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class Main {    public static void main(String[] args) {       LocalTime lt = LocalTime.parse("14:30:47");       System.out.println("The LocalTime is: " + lt);       DateTimeFormatter dtf = DateTimeFormatter.ISO_TIME;       System.out.println("The formatted LocalTime is: " + dtf.format(lt)); ... Read More

IntStream.Builder build() method in Java

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

79 Views

The build() method builds the stream. It transitions the builder to the built state. It returns the built stream. First, add elements to the streamIntStream.Builder builder = IntStream.builder(); builder.add(10); builder.add(25); builder.add(33);Now the stream is in the built phasebuilder.build().forEach(System.out::println);The syntax is as followsIntStream build()The following is an example to implement IntStream.Builder build() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream.Builder builder = IntStream.builder();       System.out.println("Elements in the stream...");       builder.add(10);       builder.add(25);       builder.add(33);       builder.add(42);       ... Read More

How to create LabelValue Tuple in Java?

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

66 Views

You can create a LabelValue tuple using the with() method or using just the constructor. Let 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 -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuplesSteps: How to run JavaTuples program in EclipseThe following is an example to create ... Read More

DoubleStream findAny() method in Java

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

80 Views

The findAny() method of the DoubleStream class returns an OptionalDouble describing some element of the stream, or an empty OptionalDouble if the stream is empty.The syntax is as followsOptionalDouble findAny()Here, OptionalDouble is a container object which may or may not contain a double value 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(23.8, 30.2, 50.5, 78.9, 80.4, 95.8);Now, display an elementOptionalDouble res = doubleStream.findAny(); The following is an example to implement DoubleStream findAny() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void ... Read More

IntStream findFirst() method in Java

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

282 Views

The findFirst() method in Java returns an OptionalInt describing the first element of this stream. If the stream is empty, an empty OptionalInt is returned.The syntax is as followsOptionalInt findFirst()Here, OptionalInt is a container object which may or may not contain an int value.To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;For OptionalInt class, import the following packageimport java.util.OptionalInt;First, create an IntStream and add elementsIntStream intStream = IntStream.of(30, 45, 70, 80, 90, 120);Now, get the first element of this streamOptionalInt res = intStream.findFirst();The following is an example to implement IntStream findFirst() method in JavaExample Live Demoimport java.util.OptionalInt; ... Read More

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

Advertisements