Found 4336 Articles for Java 8

LocalDate getDayOfYear() method in Java

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

348 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

LocalDate getDayOfMonth() method in Java

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

429 Views

The day of the month for a particular LocalDate can be obtained using the getDayOfMonth() method in the LocalDate class in Java. This method requires no parameters and it returns the day of the month which can be in the range of 1 to 31.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 month is: " + ld.getDayOfMonth());    } }OutputThe LocalDate is: 2019-02-14 ... Read More

LongStream distinct() method in Java

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

22 Views

The distinct() method in the LongStream class returns a stream consisting of the distinct elements of this stream.The syntax is as follows.LongStream distinct()To use the LongStream class in Java, import the following package.import java.util.stream.LongStream;Create a LongStream and add elements.LongStream longStream = LongStream.of(100L, 150L, 100L, 300L, 150L, 500L);Now, get the distinct elements.longStream.distinct().The following is an example to implement LongStream distinct() method in Java. Here, we have repeated elements in the stream.Example Live Demoimport java.util.stream.LongStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(100L, 150L, 100L, 300L, 150L, 500L);       System.out.println("Distinct elements..."); ... Read More

What is Decade class in JavaTuples?

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

80 Views

A Decade class is a Tuple with 10 elements. It is in the JavaTuples library. The following is the declaration −public final class Decade extends Tuple implements IValue0, IValue1 , IValue2, IValue3, IValue4, IValue5, IValue6, IValue7, IValue8, IValue9Let 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. ... Read More

LocalDate getDayOfWeek() method in Java

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

154 Views

The day of the week for a particular LocalDate can be obtained using the getDayOfWeek() method in the LocalDate class in Java. This method requires no parameters and it returns the day of the week.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 week is: " + ld.getDayOfWeek());    } }OutputThe LocalDate is: 2019-02-14 The day of the week is: THURSDAYNow let us understand ... Read More

LocalDate minusYears() Method in Java

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

569 Views

An immutable copy of the LocalDate where the years are subtracted from it can be obtained using the minusYears() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of years to be subtracted and it returns the instant with the subtracted years.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDate ld1 = LocalDate.parse("2019-02-14");       System.out.println("The LocalDate is: " + ld1);       LocalDate ld2 = ld1.minusYears(2);       System.out.println("The LocalDate after subtracting ... Read More

Create Decade Tuple from a List collection in Java

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

69 Views

Use the fromCollection() method to create a Decade tuple from a List collection in Java. 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 to run JavaTuples program in EclipseThe following is an example to create ... Read More

What is the addAtX() method of the Ennead Tuple in Java

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

59 Views

To add value in Ennead class in JavaTuples, you need to use the addAtX() method. Here, X represents the index wherein you need to add the value i.e. for index 2, use addAt2() method. Add the specific value as the parameter value of the method. For example −addAt2(“John”);Let us first see what we need to work with JavaTuples. To work with Ennead class in JavaTuples, you need to import the following package −import org.javatuples.Ennead;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