Found 4331 Articles for Java 8

Period minusYears() method in Java

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

104 Views

An immutable copy of the Period object where some years are subtracted from it can be obtained using the minusYears() method in the Period class in Java. This method requires a single parameter i.e. the number of years to be subtracted and it returns the Period object with the subtracted years.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

Period minusMonths() method in Java

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

96 Views

An immutable copy of the Period object where some months are subtracted from it can be obtained using the minusMonths() method in the Period class in Java. This method requires a single parameter i.e. the number of months to be subtracted and it returns the Period object with the subtracted months.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

Period minusDays() method in Java

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

105 Views

An immutable copy of the Period object where some days are subtracted from it can be obtained using the minusDays() method in the Period class in Java. This method requires a single parameter i.e. the number of days to be subtracted and it returns the Period object with the subtracted days.A program that demonstrates this is given as follows:Example Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

Period plusYears() method in Java

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

93 Views

An immutable copy of the Period object where some years are added to it can be obtained using the plusYears() method in the Period class in Java. This method requires a single parameter i.e. the number of years to be added and it returns the Period object with the added years.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

DoubleStream max() method in Java

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

172 Views

The max() method of the DoubleStream class returns an OptionalDouble describing the maximum element of this stream, or an empty OptionalDouble if this stream is empty.The syntax is as follows.OptionalDouble max()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 package.import java.util.stream.DoubleStream;Create a DoubleStream and add some elements.DoubleStream doubleStream = DoubleStream.of(67.9, 89.9, 10.5, 95.8, 49.6);Now, get the maximum element from the stream.OptionalDouble res = doubleStream.max();The following is an example to implement DoubleStream max() method in Java.Example Live Demoimport java.util.OptionalDouble; import java.util.stream.DoubleStream; public class Demo {    public ... Read More

Period plusMonths() method in Java

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

101 Views

An immutable copy of the Period object where some months are added to it can be obtained using the plusMonths() method in the Period class in Java. This method requires a single parameter i.e. the number of months to be added and it returns the Period object with the added months.A program that demonstrates this is given as follows:Example Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

The contains() method of the Java KeyValue Tuple

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

70 Views

Use the contains() method to search for a value in the KeyValue tuple. 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 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 implement the contains() ... Read More

LocalDate until() Method in Java

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

102 Views

The difference between two LocalDate objects can be obtained using the until() method in the LocalDate class in Java. This method requires a single parameter i.e. the end date for the LocalDate object and it returns the difference between two LocalDate objects using a Period object.A program that demonstrates this is given as follows:Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDate ld1 = LocalDate.parse("2019-01-10");       LocalDate ld2 = LocalDate.parse("2019-02-14");       System.out.println("The first LocalDate is: " + ld1);       System.out.println("The second LocalDate is: " + ... Read More

The isEmpty() method of AbstractSequentialList in Java

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

71 Views

The isEmpty() method of the AbstractSequentialList class is used to check whether the list is empty or not. If it is empty, then TRUE is returned, else FALSE.The syntax is as follows.public boolean isEmpty()To work with the AbstractSequentialList class in Java, you need to import the following package.import java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList isEmpty() method in Java.Example Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) {       AbstractSequentialList absSequential = new LinkedList();       absSequential.add(110);       absSequential.add(320); absSequential.add(400); absSequential.add(550); absSequential.add(600); absSequential.add(700); absSequential.add(900);       System.out.println("Elements ... Read More

Fetch the value from a LabelValue Tuple in Java

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

83 Views

To fetch the value from a LabelValue class in Java, you need to use the getValue() method. To get the key, use the getLabel() 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

Advertisements