TimeZonesetID() method in Java, example

TimeZone setID() method in Java, examples Original text: https://www . geesforgeks . org/time zone-setid-method-in-Java-with-examples/ The Set Identifier (String Identifier ) method of the Time Zone Class in Java is used to set the time zone Time zone identifier. No other data of the time zone object is changed during this operation. Syntax: public void setID(String *ID*) Parameters: This method takes a parameter identifier of string type, which refers to the new identification of the time zone. Return value:This method does not return a value. The following program illustrates the use of the setID() method of the time zone class:Example 1: // Java code to illustrate setID() methodimport java. util.*;public class TimeZoneDemo { public static void main(String args[]) { // Creating a TimeZone TimeZone offtime_zone = TimeZone.getTimeZone(    ”Pacific/Pago_Pago”); // set time zone ID offtime_zone .setID(“GMT+ 05:00”); // Knowing the DST System.out.println(“The ID is: ”                                                                  “>+ offtime_zone.getID()); }} Output: The ID is: GMT+05:00 Example 2: // Java code to illustrate setID() methodimport java.util.*;public class TimeZoneDemo { public static void main(String args[]) { // Creating a TimeZone TimeZone offtime_zone = TimeZone.getDefault(); // set time zone ID offtime_zone.setID(“GMT+05:30”); // Knowing the DST        System.out .println(“The ID is: ”                                                                      + offtime_zone.getID ()); }} Output: The ID is: GMT+05:30 Reference:https://docs . Oracle . com/javase/7/docs/API/Java/ util/time zone . html # setID(Java . lang . string)

Value range of () method in Java, example

Value range of () method in Java, examples Original text: https://www . geesforgeks . org/value range-of-in-Java-method-with-examples/ The () method of Value Range class helps us to get the value range based on the parameters passed to it. There are three types of () methods based on the parameters passed to it. of(long min, long max): This method helps us to get a fixed value range where the minimum and maximum values ​​are fixed . Syntax: “`javapublic static ValueRange of(long min, long max) “` Parameters:This method accepts two parameters: Minutes is the minimum value Maximum valueThat is, the maximum value Return value:This method returns the minimum value and maximum value Value range, not empty. Exception: If the minimum value is greater than the maximum value, this method throws IllegalArgumentException . The following program illustrates the ValueRange.of(long min, long max) method:Program 1: “`java// Java program to demonstrate// ValueRange.of(long min, long max) method import java.time.temporal.ValueRange; public class GFG {          public static void main(String[] args)                                                                                                                                                                                                . of (0, 66666); // Print Results System.out.println (“Valurange:” + vrange.tostring ()); } } “` Output: “`javaValueRange: 0 – 66666 “ ` of(long min, long maxSmallest, long maxLargest): This method helps us to get a variable value range where…

FieldsetDouble() method in Java, example

Field setDouble() method in Java, examples Original text: https://www . geesforgeks . org/field-set double-method-in-Java-with-examples/ setDouble()Java . lang . reflect . field method, used to set the value of the field to a double on the specified object precision value. When you need to set the value of an object field to a double, you can use this method to set the value on the object. Syntax: public void setDouble(Object obj, double d ) throws IllegalArgumentException , IllegalAccessException Parameters:This method accepts two parameters : obj :Which object field should be modified d :Yes The new value of the obj field being modified. Return: This method does not return anything. Exception: This method throws the following exception: IllegalAccessException: If this field object is implementing Java language access control, and The underlying field is inaccessible or final. IllegalArgumentException: if the specified object is not an instance of the class or interface in which the underlying field (or its subclass or implementer) is declared, or if the unwind conversion fails. NullPointerException: If the specified object is null and the field is an instance field. ExceptionInInitializerError: If the initialization caused by this method fails. The following program illustrates the setDouble() method:Program 1: // Java program…

TreeSet ceiling() method in Java, example

TreeSet ceiling() method in Java, example Original text: https://www . geesforgeks . org/treeset-ceiling-method-example in java/ The ceiling() method of Java . util . treeset class is used to return the minimum element in the set that is greater than or equal to the given element, if there is no such element , returns null. Syntax: public E ceiling(E e) Parameters:This method will The valuee serves as the parameter to be matched. Return value: This method returns the smallest element that is greater than or equal to e, or null value if there is none. Exception: If the specified element is null and the collection uses natural ordering or its comparator does not allow null elements, this method throws Null pointer exception . The following is an example to illustrate the upper limit() method Example 1: // Java program to demonstrate// ceiling() methodimport java.util.*;public class GFG1 { public static void main(String[] argv ) throws Exception { try {                                                      “>// create tree set object TreeSet<Integer > treeadd = new TreeSet<Integer>();                                                                                             “n”>treeadd.add(10); treeadd. add(20); treeadd.add(30);                                                                         treeadd.add(40); // Print the TreeSet System.out.println(“TreeSet: ” + treeadd); // getting ceiling value for 25                                                                                                               > = treeadd.ceiling(25);                                                          “c1”>// printing the ceiling value System.out.println(“Ceiling value for 25: ”                                                                          >); } catch (NullPointerException e) {  System.out.println(“Exception thrown : ” span> +…

ChronoLocalDate format() method in Java, example

ChronoLocalDate format() method in Java, examples Original text: https://www . geeksforgeeks . org/chronolocaldata-format-method-in-Java-with-examples/ The format() method of the ChronalDate interface in Java formats the date using the specified formatter. Syntax : public String format(DateTimeFormatter formatter) Parameters: This method accepts One parameter obj that specifies the formatter to use, and is not empty. Exception: This function only throws datetime exception that occurs when printing errors. Return value: Returns a formatted date string, not empty. The following program illustrates the format() method in Java: Program 1 : // Program to illustrate the format() methodimport java.util.*;import java.time.*;import java .time.chrono.*;import java.time .format.DateTimeFormatter;public class GfG { public static void main(String[] args) { // Parses the date ChronoLocalDate dt = LocalDate. parse(“2018-11-01”); System. out.println(dt); // Function call DateTimeFormatter formatter = DateTimeFormatter              .ofPattern(“dd /MM/YYYY”); System.out.println( formatter.format(dt)); } } Output: 2018-11-0101/ 11/2018 Procedure 2: Give examples of exceptions. // Program to illustrate the format() method // Exception Programimport java.util.*; import java.time.*; import java.time.chrono.*;import java.time.format.DateTimeFormatter;public class GfG { public static void main(String[] args) { try { // Parses the date ChronoLocalDate dt = LocalDate.parse(“2018-01-32”); System.out .println(dt); // Function call  DateTimeFormatter formatter     = DateTimeFormatter .ofPattern(“dd/ MM/YYYY”); System.out.println(formatter.format (dt)); } catch (Exception e ) {                                                           “p”>.out.println(e); }  }} Output: java.time.format. DateTimeParseException: Text ‘2018-01-32’ could not be parsed: Invalid value for DayOfMonth (valid values 1 – 28/31): 32 Reference: https://docs . Oracle . com/javase/9/docs/API/Java/time/chrono/chronolocaldata .…

PrintWriterprintln(int) method in Java, example

PrintWriter println(int) method in Java, examples Original text: https://www . geesforgeks . org/print writer-printlint-method-in-Java-with-examples/ The println(int) method of the PrintWriter class in Java prints the specified int value on the stream and then breaks the line. This int value is treated as a parameter. Syntax: public void println(int intValue) Parameters:This method accepts A mandatory parameter intValue which is the int value to be written to the stream. Return value:This method does not return a value. The following method illustrates how the println(int) method works: Program 1: // Java program to demonstrate// PrintWriter println(int) methodimport java.io.*;class GFG { public static void main(String[] args ) { try {                                                                                                                                  = new PrintWriter (System.out); // Print the int value ‘4’                                                                                                                                                 () method // This will put the intValue in the // stream till it is printed on the console printr.println(4);                                                  .flush(); } catch (Exception e) {   System.out.println(e);  } }} Output: 4 Program 2: // Java program to demonstrate// PrintWriter println(int) methodimport java.io.*;class GFG { public static void main(String[] args) { try {                                                                         Create a PrintWriter instance PrintWriter printr                                               /span> new PrintWriter( System.out);                                 class=”c1″>// Print the int value ’65’   // to this stream using println() method   // This will put the intValue in the // stream till it is printed on the console printr.println(65); printr.flush (); } catch (Exception e) { System.out.println(e); } }} Output: 65

ZoneOffsethashCode() method in Java, example

ZoneOffset hashCode() method in Java, examples Original text: https://www . geesforgeks . org/zone offset-hashcode-method-in-Java-with-examples/ java.time packageThe hashCode() method of the ZoneOffset class is used to obtain the ZoneOffset instance. hashCode value. This method accepts no parameters and returns an int value. This is the hashCode value. Syntax: public static int hashCode() Parameters:This method does not accept any parameters. Return value: This method returns an integer value that is the hash value of this ZoneOffset instance. The following example illustrates the ZoneOffset.hashCode() method: Example 1: // Java code to illustrate hashCode() methodimport java. time.*;public class GFG { public static void main(String[] args) { // Get the ZoneOffset ZoneOffset zoneOffset = ZoneOffset.ofHours(5 ); System.out.println(zoneOffset ); // Using hashCode() method int hashCode = zoneOffset. hashCode(); System.out.println (“ZoneOffset hashCode: ” + hashCode); } } Output: +05:00 ZoneOffset hashCode: 18000 Example 2: // Java code to illustrate hashCode() methodimport java.time.*;public class GFG { public static void main(String[] args) { // Get the ZoneOffset ZoneOffset zoneOffset = ZoneOffset.of(“Z”);     System.out. println(zoneOffset); // Using hashCode() method int hashCode = zoneOffset.hashCode(); System. out.println(“ZoneOffset hashCode: ” + hashCode);}} Output: ZZoneOffset hashCode: 0 Reference: Oracle Documentation

HijrahDate minus (long, temporary) method in Java, example

HijrahDate minus (long, temporary) method in Java, example Original text: https://www . geesforgeks . org/hijrahdate-mins long-tempalalunit-method-in-Java- with-example/ The Subtract() method of Java . time . chrono . HijrahDate class is used to extract the current hijrah date from Get the hijrah date after subtracting a certain number of tense accessor units. Syntax: public HijrahDate minus(long amountToSubtract, TemporalUnit unit) Parameters: This method takes the following parameters as parameters: Amount to Subtract: is the time unit value to be subtracted from the current Hijra date. Unit: is an object of time unit or hour unit. Return value:This method subtracts one time access from the current Hijri date After the device unit, returns the Hijri date. The following is an example of the subtract() method: Example 1: Java // Java program to demonstrate minus() methodimport java.util.*; import java.io.*;import java.time.*;import java.time.chrono.*;import java.time.temporal.*;public class GFG { public static void main( String[] argv) { try {                                                                                                             /span> hidate = HijrahDate .now();                                                                                           /span> System.out.println(“old hijrah date: ”                                                                                                         class=”c1″>// Subtracting hijrah date // by using minus() method HijrahDate newdate    = hidate.minus(                                                >, ChronoUnit.DAYS); // Display the result System.out. println(“new hijrah date: ”                                                                                          span> newdate); } catch (DateTimeException e ) {             System .out.println(“passed parameter can”                                                          form a date”);                                           n class=”p”>.out.println(“Exception thrown: ”                                                           =”n”>e); } }} Output: old hijrah date: Hijrah-umalqura AH 1441- 06-25new hijrah…

DoubleStreamcount() in Java, example

DoubleStream count() in Java, examples Original text: https://www . geesforgeks . org/double stream-count-Java-examples/ DoubleStream count() Returns the count of elements in the stream. DoubleStream count() exists in java.util.stream.DoubleStream, which is a special case of reduction, that is, it takes a series of input elements and combines them into an aggregated result. Syntax: long count() Note:This is aTerminal operationThat is, crossing a stream may have consequences or side effects. After a terminal operation is performed, the stream pipe is considered consumed and can no longer be used. Example 1: Count elements in a double stream. // Java code for DoubleStream count()/ / to count the number of elements in// given streamimport java.util.*;import java.util.stream.DoubleStream;class GFG { // Driver code public static void main( String[] args) { // creating a DoubleStream DoubleStream stream = DoubleStream.of(2.3 , 3.4, 4.5,                                                                              “>6.7, 7.8, 8.9); // storing the count of elements // in a variable named total long total = stream.count(); // displaying the total number of elements System.out.println (total); }} Output: 7 Example 2: Count distinct elements in two streams. // Java code for DoubleStream count()/ / to count the number of distinct// elements in given streamimport java.util.*;import java.util.stream.DoubleStream;class GFG { // Driver code public static void main (String[] args) { // creating a DoubleStream DoubleStream stream =…

Scanner has NextByte() method in Java, example

Scanner has NextByte() method in Java, examples Original text: https://www . geesforgeks . org/scanner-hasnextbyte-method-in-Java-with-examples/ If the next token in this scanner’s input can be assumed to be a byte value in a given radix, then the Java . util . scanner class The strong>hasNextByte() method returns true. The scanner will not advance past any input. If no base is passed as an argument, the function interprets the base as the default base and runs accordingly. Syntax: public boolean hasNextByte(int radix) orpublic boolean hasNextByte() Parameters: This function accepts a single parameter base, which is not mandatory. It specifies the base used to interpret tokens as byte values. Return value: This function returns true if and only if the next token for this scanner is a valid byte value in the default radix. Exception: If the scanner is closed, this function will throw an Illegal status exception. The following program illustrates the above functionality: Program 1: // Java program to illustrate the// hasNextByte() method of Scanner class in Java// with parameterimport java.util.*;public class GFG1 { public static void main(String[] argv) throws Exception { String s = “gfg 2 geeks!”; span> // new scanner with the // specified String Object Scanner scanner = new Scanner(s); // use US locale to…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索