Nancy Den has Published 290 Articles

LocalTime getSecond() method in Java

Nancy Den

Nancy Den

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

138 Views

The second of minute for a particular LocalTime can be obtained using the getSecond() method in the LocalTime class in Java. This method requires no parameters and it returns the second of the minute in the range of 0 to 59.A program that demonstrates this is given as followsExample Live Demoimport ... Read More

LocalTime hashCode() method in Java

Nancy Den

Nancy Den

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

144 Views

The hash code value of the LocalTime can be obtained using the hashCode() method in the LocalTime class in Java. This method requires no parameters and it returns the hash code value of the LocalTime.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo { public ... Read More

LocalTime ofSecondOfDay() method in Java

Nancy Den

Nancy Den

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

106 Views

A LocalTime object can be obtained using the seconds of the day with the ofSecondOfDay() method in the LocalTime class in Java. This method requires a single parameter i.e. the seconds of the day and it returns the LocalTime object for the seconds of the day.A program that demonstrates this ... Read More

LocalTime equals() method in Java

Nancy Den

Nancy Den

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

473 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 ... Read More

Iterate through KeyValue Tuple in Java

Nancy Den

Nancy Den

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

467 Views

To iterate through the KeyValue tuple in Java, use the Iterable and loop it through using the for loop. 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 ... Read More

How to get days, months and years between two Java LocalDate?

Nancy Den

Nancy Den

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

1K+ Views

Set the two Java dates:LocalDate date1 = LocalDate.of(2019, 3, 25); LocalDate date2 = LocalDate.of(2019, 4, 29);Now, get the difference between two dates with Period class between() method:Period p = Period.between(date1, date2);Now, get the years, month and days:p.getYears() p.getMonths() p.getDays()Exampleimport java.time.LocalDate; import java.time.Period; public class Demo {    public static void ... Read More

How to check whether the given date represents weekend in Java

Nancy Den

Nancy Den

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

2K+ Views

At first, display the current date:LocalDate date = LocalDate.now();Now, get the day of week from the above Date (current date):DayOfWeek day = DayOfWeek.of(date.get(ChronoField.DAY_OF_WEEK));On the basis of the above result, use SWITCH to check for the current day. If the day is SATURDAY/SUNDAY, then it’s Weekend.Exampleimport java.time.DayOfWeek; import java.time.temporal.ChronoField; import java.time.LocalDate; ... Read More

What is StringJoiner class in Java 8?

Nancy Den

Nancy Den

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

255 Views

The StringJoiner class in Java 8 constructs a sequence of characters. This sequence is separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix.The following are the constructors of the StringJoiner class:StringJoiner(CharSequence delimiter): This constructor constructs a StringJoiner with no characters in it ... Read More

How to count days between two dates in Java

Nancy Den

Nancy Den

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

1K+ Views

Let us first set two dates:LocalDate date1 = LocalDate.of(2019, 4, 16); LocalDate date2 = date1.with(Month.MAY).withDayOfMonth(04);Now, count the dates between both the above dates using between():int numDays = Period.between(date1, date2).getDays();Exampleimport java.time.LocalDate; import java.time.Month; import java.time.Period; public class Demo {    public static void main(String[] argv) {       LocalDate date1 ... Read More

StringJoiner toString() method in Java 8

Nancy Den

Nancy Den

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

292 Views

The toString() method of the StringJoiner class in Java8 is used to return the string representation of the StringJoiner.The syntax of the toString() method is as follows:String toString()To work with the StringJoiner in Java 8, import the following package:import java.util.StringJoiner;The following is an example to implement StringJoiner toString() method in ... Read More

Advertisements