Krantik Chavan has Published 308 Articles

MonthDay isAfter() Method in Java

Krantik Chavan

Krantik Chavan

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

73 Views

It can be checked if a particular MonthDay is after the other MonthDay in a timeline using the isAfter() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object that is to be compared. It returns true if the MonthDay object is after ... Read More

Java Program to get date for all the days of the current week

Krantik Chavan

Krantik Chavan

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

565 Views

At first, get the current date:LocalDate listDays = LocalDate.now();Now, get the date for all the days of the current week:Arrays.asList(DayOfWeek.values()).stream().map(listDays::with).collect(toList()));Exampleimport java.time.DayOfWeek; import java.time.LocalDate; import java.util.Arrays; import static java.util.stream.Collectors.toList; public class Demo {    public static void main(String[] args) {       LocalDate listDays = LocalDate.now();       System.out.println("All ... Read More

What is the most efficient way to check the presence of a row in a MySQL table?

Krantik Chavan

Krantik Chavan

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

217 Views

The most efficient want to check the presence of a row, use the count():select count(1) from yourTableName where yourCondition;Let us first create a table:mysql> create table DemoTable (    Id int,    FirstName varchar(20) ); Query OK, 0 rows affected (0.73 sec)Following is the query to insert some records in ... Read More

Java Program to adjust LocalDate to last Day of Month with TemporalAdjusters class

Krantik Chavan

Krantik Chavan

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

2K+ Views

Let us first set a date:LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15)Now, adjust LocalDate to last Day of month;LocalDate day = localDate.with(TemporalAdjusters.lastDayOfMonth());Exampleimport java.time.LocalDate; import java.time.Month; import java.time.temporal.TemporalAdjusters; public class Demo {    public static void main(String[] args) {       LocalDate localDate = LocalDate.of(2019, Month.JUNE, 15);       System.out.println("Current ... Read More

How to update a range of records in MySQL?

Krantik Chavan

Krantik Chavan

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

739 Views

To update a range of records in MySQL, you can use BETWEEN. Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20),    Age int ); Query OK, 0 rows affected (0.53 sec)Following is the query to insert some ... Read More

MonthDay isSupported() Method in Java

Krantik Chavan

Krantik Chavan

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

65 Views

It can be checked if a ChronoField is supported by the MonthDay class or not by using the isSupported() method in the MonthDay class in Java. This method requires a single parameter i.e. the ChronoField to check. It returns true if the ChronoField is supported by the MonthDay class and ... Read More

Java Program to convert HashSet to Enumeration

Krantik Chavan

Krantik Chavan

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

143 Views

Let’s say the following is our HashSet:HashSet set = new HashSet(); set.add("P"); set.add("Q"); set.add("R"); set.add("S"); set.add("T"); set.add("U"); set.add("V"); set.add("W"); set.add("X"); set.add("Z");Now convert the above HashSet to Enumeration:Enumeration enumeration = Collections.enumeration(set); while (enumeration.hasMoreElements())    System.out.println(enumeration.nextElement());Exampleimport java.util.Collections; import java.util.Enumeration; import java.util.HashSet; public class Demo {    public static void main(String[] args) ... Read More

Can we ignore duplicate rows in COUNT?

Krantik Chavan

Krantik Chavan

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

4K+ Views

Yes, we can ignore duplicate rows in COUNT using DISTINCT. Following is the syntax:select count(distinct yourColumnName) from yourTableName;In MySQL, COUNT() will display the number of rows. DISTINCT is used to ignore duplicate rows and get the count of only unique rows.Let us first create a table:mysql> create table DemoTable ( ... Read More

MonthDay isValidYear() Method in Java

Krantik Chavan

Krantik Chavan

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

69 Views

It can be checked if a year is valid or not for a MonthDay object using the isValidYear() method in the MonthDay class in Java. This method requires a single parameter i.e. the year which is to be checked. Also, it returns true if the year is valid for a ... Read More

Java Program to convert Instant to LocalDateTime

Krantik Chavan

Krantik Chavan

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

394 Views

Let’s say you need to convert Instant to LocalDateTime with IST with timezone:Create an Instant:Instant instant = new Date().toInstant();Now, convert Instant to LocalDateTime:LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.of(ZoneId.SHORT_IDS.get("IST")));Exampleimport java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       Instant instant ... Read More

Advertisements