Found 4335 Articles for Java 8

Create Octet Tuple using with() method in Java

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

61 Views

You can easily create Octet Tuple in Java using with() method. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package.import org.javatuples.Octet;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 Octet Tuple using with() ... Read More

How to create Octet Tuple in Java?

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

85 Views

An Octetclass is a Tuple of 8 element. It is in the JavaTuples library. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package.import org.javatuples.Octet;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 Octet ... Read More

What is AbstractCollection class in Java?

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

375 Views

The AbstractCollection class provides an implementation of the Collection interface. This is done to minimize the effort in the implementation of this interface.For an unmodifiable collectionExtend this class and provide implementations for the iterator and size methods.For modifiable collectionAdditionally override the add() method of the class. The iterator method returns the iterator and it must implement the remove() method.The syntax is as follows.public abstract class AbstractCollection extends Object implements CollectionHere, Object is the root of the class hierarchy and Collection is a group of objects.To work with AbstractCollection class in Java, import the following package.import java.util.AbstractCollection;Let us now see an ... Read More

StringJoiner setEmptyValue() method in Java 8

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

272 Views

The setEmptyValue() method of the StringJoiner class in Java 8 sets the sequence of characters. These characters are to be used when determining the string representation of this StringJoiner and when it is empty. That would be none of the elements have been added.The syntax is as followspublic StringJoiner setEmptyValue(CharSequence emptyVal)Here, emptyVal are the characters to return as the value of an empty StringJoinerTo work with the StringJoiner in Java 8, import the following package.import java.util.StringJoiner;The following is an example to implement StringJoiner setEmptyValue() method in Java:Example Live Demoimport java.util.StringJoiner; public class Demo {    public static void main(String[] args) { ... Read More

LocalDateTime getDayOfYear() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

40 Views

The day of the year for a particular LocalDateTime can be obtained using the getDayOfYear() method in the LocalDateTime 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 follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:30:15");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The day of the year is: " + ... Read More

LocalDateTime getHour() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

87 Views

The hour of the day for a particular LocalDateTime can be obtained using the getHour() method in the LocalDateTime class in Java. This method requires no parameters and it returns the hour of the day which can range from 0 to 23.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The hour is: " + ldt.getHour());    } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The hour is: 15Now let ... Read More

LocalDateTime getYear() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

368 Views

The year for a particular LocalDateTime can be obtained using the getYear() method in the LocalDateTime 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 follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The year is: " + ldt.getYear());    } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The year is: 2019Now let us understand the above program.First the ... Read More

LocalDateTime equals() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

72 Views

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

LocalDateTime withNano() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

116 Views

An immutable copy of a LocalDateTime with the nanoseconds altered as required is done using the method withNano() in the LocalDateTime class in Java. This method requires a single parameter i.e. the nanosecond that is to be set in the LocalDateTime and it returns the LocalDateTime with the nanosecond altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ldt2 = ldt1.withNano(5);       ... Read More

LocalDateTime plusWeeks() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

62 Views

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

Advertisements