Found 4331 Articles for Java 8

DoubleStream concat() method in Java

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

78 Views

The concat() method of the DoubleStream class creates a stream which is concatenated. The elements of the resultant stream are all the elements of the first stream followed by all the elements of the second stream.The syntax is as follows.static DoubleStream concat(DoubleStream streamOne, DoubleStream streamTwo)Here, streamOne is the first stream whereas streamTwo is the second stream.To use the DoubleStream class in Java, import the following package.import java.util.stream.DoubleStream;Create a DoubleStream with some elements.DoubleStream doubleStream1 = DoubleStream.of(20.5, 30.6, 58.9, 66.7);Create another DoubleStream.DoubleStream doubleStream2 = DoubleStream.of(71.8, 77.9, 82.3, 91.6, 98.4);Now, concat the streamsDoubleStream.concat(doubleStream1, doubleStream2)The following is an example to implement DoubleStream concat() method ... Read More

LocalDate getYear() method in Java

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

5K+ Views

The year for a particular LocalDate can be obtained using the getYear() method in the LocalDate class in Java. This method requires no parameters and it returns the year which can range from MIN_YEAR to MAX_YEAR.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2019-02-14");       System.out.println("The LocalDate is: " + ld);       System.out.println("The year is: " + ld.getYear());    } }OutputThe LocalDate is: 2019-02-14 The year is: 2019Now let us understand the above program.First the LocalDate ... Read More

Create LabelValue Tuple from a List collection in Java

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

60 Views

To create LabelValue tuple from a List collection, use the fromCollection() method. Here, we will be creating LabelValue from List, therefore use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following package −import 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 JavaTuples −Steps − ... Read More

LongStream average() method in Java

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

336 Views

The average() method of the LongStream class in Java returns an OptionalDouble describing the arithmetic mean of elements of this stream, or an empty optional if this stream is empty.The syntax is as follows.OptionalDouble average()Here, OptionalDouble is a container object which may or may not contain a double value.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;Create LongStream and add elements.LongStream longStream = LongStream.of(100L, 150L, 180L, 200L, 250L, 300L, 500L);Get the average of the elements in the stream.OptionalDouble res = longStream.average();The following is an example to implement LongStream average() method in Java.Example Live Demoimport java.util.*; import java.util.stream.LongStream; public ... Read More

LocalDate getMonth() method in Java

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

3K+ Views

The month name for a particular LocalDate can be obtained using the getMonth() method in the LocalDate class in Java. This method requires no parameters and it returns the month name in the year.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2019-02-14");       System.out.println("The LocalDate is: " + ld);       System.out.println("The month is: " + ld.getMonth());    } }OutputThe LocalDate is: 2019-02-14 The month is: FEBRUARYNow let us understand the above program.First the LocalDate is displayed. ... Read More

How to create LabelValue Tuple from an array in Java

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

74 Views

To create LabelValue tuple from an array, use the fromArray() method. First, create an array and add elements to it. After that, use the fromArray() method to create a Tuple and set the array in it.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following package −import 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 ... Read More

LongStream concat() method in Java

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

66 Views

The concat() method in the LongStream class creates a concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.The syntax is as follows.static LongStream concat(LongStream one, LongStream two)Here, parameter one is the 1st stream, whereas two is the 2nd stream. The method returns the concatenation of both the streams.To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;Create a LongStrem and add some elements.LongStream streamOne = LongStream.of(100L, 150L, 300L, 500L);Now, create another stream.LongStream streamTwo = LongStream.of(200L, 250L, 400L, 600L, 550L);To concatenate both the above streams, use the ... Read More

LocalDate getDayOfYear() method in Java

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

350 Views

The day of the year for a particular LocalDate can be obtained using the getDayOfYear() method in the LocalDate class in Java. This method requires no parameters and it returns the day of the year which can be in the range of 1 to 365 and also 366 for leap years.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDate ld = LocalDate.parse("2019-02-14");       System.out.println("The LocalDate is: " + ld);       System.out.println("The day of the year is: " + ld.getDayOfYear()); ... Read More

LongStream count() method in Java

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

76 Views

The count() method of the LongStream class in Java is used to return the count of elements in this stream.The syntax is as follows.long count()To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;Create a LongStream and add some elements.LongStream longStream = LongStream.of(50L, 30L, 80L, 40L, 15L, 60L);Now, get the count of elements.longStream.count()The following is an example to implement LongStream count() method in Java.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(50L, 30L, 80L, 40L, 15L, 60L);       System.out.println("The number of elements in the ... Read More

How to create Decade Tuple in Java?

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

65 Views

Create Decade Tuple in Java using a constructor or with() method. Here, we will see how to create a Decade of Tuple using constructor.Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following package −import org.javatuples.Decade;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 JavaTuples −Steps − How ... Read More

Advertisements