MonthDay query() method in Java with Examples Last Updated : 10 Jan, 2019 Comments Improve Suggest changes Like Article Like Report query() method of an MonthDay class used to query this MonthDay using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this MonthDay. Syntax: public <R> R query(TemporalQuery<R> query) Parameters: This method accepts only one parameter query which is the query to invoke. Return value: This method returns the query result, null may be returned. Exception: This method throws following Exceptions: DateTimeException - if unable to query . ArithmeticException - if numeric overflow occurs. Below programs illustrate the query() method: Program 1: Java // Java program to demonstrate // MonthDay.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create MonthDay object MonthDay lt = MonthDay.parse("--12-09"); // apply query method of MonthDay class String value = lt.query( TemporalQueries.chronology()) .toString(); // print the result System.out.println("chronology value" + " for MonthDay is " + value); } } Output: chronology value for MonthDay is ISO Program 2: Showing if query did not found the required object then it returns null. Java // Java program to demonstrate // MonthDay.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create MonthDay object MonthDay lt = MonthDay.parse("--12-07"); // apply query method of MonthDay class // print the result System.out.println("offset value" + " for MonthDay is " + lt.query( TemporalQueries.offset())); } } Output: offset value for MonthDay is null References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#query(java.time.temporal.TemporalQuery) Comment More infoAdvertise with us Next Article MonthDay query() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-MonthDay Practice Tags : Java Similar Reads MonthDay range() method in Java with Examples range() method of the MonthDay class used to get the ValueRange object which is the range of field in terms of the minimum and maximum values for the field passed as a parameter to this method. The method returns ValueRange object only for those fields which are supported by MonthDay object. So when 2 min read MonthDay with() Method in Java with Examples with(Month month) method of the MonthDay class used to alter the month-of-year of MonthDay object using month passed as a parameter and after that method returns the copy of altered MonthDay.If the day-of-month value is invalid for the specified month after altering operation, the day will be adjust 2 min read MonthDay get() method in Java with Examples The get() method of MonthDay class in Java gets the value of the specified field from this month-day as an int. Syntax: public int get(TemporalField field) Parameter: This method accepts a parameter field which specifies the field to get and not null. Returns: The function returns the value for the 2 min read MonthDay toString() Method in Java with Examples toString() method of the MonthDay class used to represents this month-day as a String like --08-23.The output will be in the format --MM-dd:Syntax: public String toString() Parameters: This method did not accepts any parameter.Return value: This method returns a String representation of this MonthDa 1 min read MonthDay from() method in Java with Examples The from() method of MonthDay class in Java obtains an instance of MonthDay from a temporal object. Syntax: public static MonthDay from(TemporalAccessor temporal) Parameter: This method accepts a parameter temporal which specifies the temporal object to convert which is not null. Returns: The functi 1 min read Like