Calendar clone() method in Java, example
Calendar clone() method in Java, examples Original text: https://www . geesforgeks . org/calendar-clone-method-in-Java-with-examples/ The clear() method in the Calendar class is used to clone the calendar object. It basically creates a shallow copy of this object. Syntax: public Object clone() Parameters: This method does not take any parameters. Return value:This method does not return a value. The following program illustrates the working of the clone() method of the Calendar class:Example 1: // Java Code to illustrate clone() Methodimport java. util.Calendar;public class CalendarClassDemo { public static void main(String args[]) { // Creating a calendar object Calendar calndr1 = Calendar.getInstance(); // Displaying current calendar System.out. println(“Original calendar: ” + calndr1.getTime()); // Cloning the original Calendar calndr2 = (Calendar)calndr1.clone(); // Displaying the Copy System.out.println(“Cloned calendar: ” “>+ calndr2.getTime()); }} Output: Original calendar: Tue Feb 12 11:41:36 UTC 2019Cloned calendar: Tue Feb 12 11:41:36 UTC 2019 Example 2: // Java Code to illustrate clone() Methodimport java.util.*;public class CalendarClassDemo { public static void main(String args[]) { // Creating a calendar object Calendar calndr1 new GregorianCalendar(2018, 12, 2); // Displaying current calendar System.out.println(“Original calendar: ” + calndr1.getTime()); // Cloning the original Calendar calndr2 = (Calendar)calndr1.clone(); // Displaying the Copy System.out.println(“Cloned calendar: ” + calndr2.getTime ()); }} Output: Original calendar: Wed Jan 02 00:00:00 UTC 2019Cloned calendar: Wed Jan 02 00:00:00 UTC 2019 Reference:https://docs . Oracle . com/javase/7/docs/API/Java/util/calendar…
ZoneOffsetofTotalSeconds(int) method in Java, example
ZoneOffset ofTotalSeconds(int) method in Java, example Original text: https://www . geesforgeks . org/zone offset-of total secondsint-method-in-Java-with- examples/ The ofTotalSeconds(int) method of the ZoneOffset class in the java.time package is used Get an instance of ZoneOffset using the offset in TotalSeconds passed as parameter. This method takes totalSeconds as an argument as an int and converts it to a ZoneOffset. Syntax: public static ZoneOffset ofTotalSeconds(int totalSeconds) Parameters: This method accepts a parameter totalSeconds, which will be converted from int to a ZoneOffset instance. Its range is -64800 to +64800. Return Value: This method returns a ZoneOffset instance parsed from the specified totalSeconds. Exception: If totalSeconds is invalid, this method throws DateTimeException. The following example illustrates the ZoneOffset.ofTotalSeconds() method: Example 1: // Java code to illustrate ofTotalSeconds() methodimport java. time.*;public class GFG { public static void main(String[] args) { // Get the totalSeconds int totalSeconds = 5000; span> = ZoneOffset.ofTotalSeconds(totalSeconds); System.out. span>println(zoneOffset) ; }} Output: +01:23:…
StringReader reading (char[]) method in Java, example
StringReader reading (char[]) method in Java, example Original text: https://www . geesforgeks . org/string reader-readchar-method-in-Java-with- examples/ The method of read(char[])StringReader class in Java is to read the specified characters into an array. This method blocks the stream until: It takes some input from the stream. Some IOException occurred. It has reached the end of the stream when reading. Grammar: public int read( char[] charArray) Parameters: This method accepts a mandatory parameter character array, which is to be written Array of characters in the stream. Return value: This method returns an integer value, which is the number of characters read from the stream. If no characters were read, -1 is returned. Exception: If an error occurs during input and output, this method throws Exception. The following method illustrates how the read(char[]) method works: Program 1: // Java program to demonstrate// StringReader read(char[]) method import java.io.*;import java.util.*;class GFG { public static void main(String[] args ) { try { String str = “GeeksForGeeks”; “>StringReader reader = new StringReader(str); span class=”kt”>char[] charArray = new char[5 ]; /span>read(charArray ); // Print the read charArray System.out.println( Arrays .toString(charArray)); reader.close(); } catch (Exception e) { System.out.println(e ); } }} Output: [G, e, e, k, s] Procedure 2: // Java program to demonstrate// StringReader read(char[]) methodimport java.io.*;import java.util.*;class…
Abstract sequential list clear() method in Java, example
Abstract sequential list clear() method in Java, example Original text: https://www . geesforgeks . org/abstractsequentialist-clear-method-in-Java-with-example/ The clear() method of Abstract Sequential List in Java is used to remove all elements from the list. After the call returns, the list will be empty. Syntax: public void clear() Parameters: This function has no parameters. Return:This method does not return a value. It removes all elements from the list and makes it empty. The following example illustrates the AbstractSequentialList.clear() method: Example 1: // Java code to demonstrate the working of// clear() method in AbstractSequentialListimport java.util.*;public class GFG { public static void main(String[] args) { // creating an AbstractSequentialList AbstractSequentialList<Integer> arr = new LinkedList<Integer>(); // using add() to initialize values // [1, 2, 3, 4] arr.add(1); arr.add (2); arr.add(3 ); arr.add(4); // list initially System.out.println(“The list initially: ” >); // clear function used arr.clear(); // list after clearing all elements System.out.println(“The list after ” + “using clear() method: ” >+ arr); }} Output: The list initially: [1, 2, 3, 4]The list after using clear () method: [] Example 2: // Java code to demonstrate the working of// clear() method in AbstractSequentialListimport java.util.*;public class GFG { public static void main(String[] args) { // creating an AbstractSequentialList AbstractSequentialList<String> arr = new LinkedList<String>(); // using add() to initialize values // [Geeks, For, ForGeeks, GeeksForGeeks] arr. span>add(“Geeks”); arr.add(“For”); arr.add(“ForGeeks”); arr. add(“GeeksForGeeks”); // list…
Isochronous decomposition() method in Java, example
Isochronomics-resolved ate-method-in-Java-with-example/ The resolveDate() method of the Java . time . chrono . isochronology class is used to retrieve data based on the Iso calendar in a specific parser style. Retrieve local dates with the help of parsing the chrono field associated with a specific long value in the map. Syntax: public LocalDate resolveDate( Map fieldValues, ResolverStyle resolverStyle) Parameters:This method takes the following parameters as parameters: Field value: This will contain the timing field. Parser Style: This will parse the time field and provide the date. Return value:This method parses the Chrono field in the map associated with a specific long value , returns a local date based on the Iso calendar using a specific parser style. The following example illustrates the resolveDate() method: Example 1: // Java program to demonstrate// resolveDate() methodimport java.util.*;import java.io.*;import java.time.*;import java.time.chrono.*;import java.time.temporal.*;import java.time.format.*;public class GFG { public static void main(String[] argv) { try { hidate = LocalDate.now(); getting IsoChronology // used in LocalDate IsoChronology crono = hidate.getChronology(); // creating and initializing HashMap HashMap<TemporalField, Long> map = new HashMap<TemporalField, Long>(); span class=”p”>.put((TemporalField) “>EPOCH_DAY, 30l); >// by using resolveDate() method n”>crono.resolveDate( “n”>ResolverStyle.LENIENT); class=”na”>out.println( “LocalDate is : ” “p”>); } catch (DateTimeException e) { System.out.println(“passed parameter can ” + ” not form a date”); System.out.println(“Exception thrown: ” =”p”>} }} Output: LocalDate is…
Readerreset() method in Java, example
Reader reset() method in Java, examples Original text: https://www . geesforgeks . org/reader-reset-method-in-Java-with-examples/ The reset() method of the Reader class in Java is used to reset the stream. After reset, if the stream has been marked, this method attempts to reposition it at the mark, otherwise it attempts to position it to the starting point. Syntax: public void reset() Parameters: This method does not accept any parameters. Return value:This method does not return a value. Exception:If an error occurs during input and output If the stream is not marked If the tag is invalid If the reset () method is not supported, this method throws IOException: . The following method illustrates how the reset() method works: Program 1: // Java program to demonstrate// Reader reset() methodimport java.io.*;import java.util.*;class GFG { public static void main (String[] args) { try { String str = “GeeksForGeeks”; Reader instance > new StringReader(str); // Get the character // to be read from the stream int ch; // Read the first 10 characters // to this reader using read() method // This will put the str in the stream // till it is read by the reader > for (int i = 0; i < 10; i++) { ch = reader. span>read(); System.out.print((char)ch); } System.out.println(); // mark the stream for // 5…
ScanneruseLocale() method in Java, example
Scanner useLocale() method in Java, examples Original text: https://www . geesforgeks . org/scanner-uselocale-method-in-Java-with-examples/ The useLocale() method of the Java . util . scanner class sets the scanner’s locale to the specified locale. Syntax: public Scanner useLocale(Locale locale) Parameters:This function accepts A mandatory parameter Locale that specifies a string specifying the locale to use. Return Value: This function returns the modified scanner. Exception: if the base is less than characters. Minimum baseor greater thancharacters. MAX_RADIX, then throw IllegalArgumentException. The following program illustrates the above functionality: Program 1: // Java program to illustrate the// Scanner useLocale() method in Javaimport java.util.*;public class GFG1 { public static void main(String[] argv ) throws Exception { String s = “Geeksforgeeks has Scanner Class Methods”; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print a line of the scanner System.out.println(“Scanner String: \ n” + scanner.nextLine()); // display the previous locale System.out.println(“Current Lcoale: ” span class=”o”>+ scanner.locale()); // change the locale of the scanner scanner.useLocale(Locale.ENGLISH); System.out.println(“Changing Locale to ENGLISH”); // display the new locale System.out.println (“Updated Locale: ” “n”>scanner.locale()); // close the scanner scanner. close(); }} Output: Scanner String: Geeksforgeeks has Scanner Class MethodsCurrent Lcoale: en_USChanging Locale to ENGLISHUpdated Locale: en Program 2: // Java program to illustrate the// Scanner useLocale() method in Javaimport java.util.*;public class GFG1 {…
ParsePositiontoString() method in Java, example
ParsePosition toString() method in Java, example Original text: https://www . geesforgeks . org/parse position-tostring-method-in-Java-with-example/ The toString() method of the java.text.ParsePosition class is used to retrieve the parse position object represented as a string. Syntax: public String toString() Parameters : This method does not accept any parameters as parameters. Return value:This method returns the parsed location object represented as a string. The following is an example of the toString() method:Example 1: Java language (a computer language, especially Create a website) // Java program to demonstrate// toString() methodimport java.text.*;import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // new ParsePosition Object ParsePosition pos >= new ParsePosition(500); // setting error index pos.setErrorIndex(30); // getting string representation // of this ParsePosition Object /span> i = pos .toString(); span> System.out.println( span> class=”p”>} catch (ClassCastException e) { System.out.println(e); } }} Output: ParsePosition: java.text. ParsePosition[index=500,errorIndex=30] Example 2: Java language (a computer language, especially used for creating websites) // Java program to demonstrate// toString() methodimport java.text.*;import java.util.*;import java.io.*;public class GFG { public static void main(String[] argv) { try { // Creating and initializing // new ParsePosition Object ParsePosition pos > new ParsePosition(-1); // setting error index pos.setErrorIndex (3000); span> class=”n”>String i = pos .toString(); “>// display result System.out.println( “>”ParsePosition: ” + i); } catch (ClassCastException e) { System.out .println(e); } }} Output: ParsePosition:…
CompositeNameget() method in Java, example
CompositeName get() method in Java, examples Original text: https://www . geesforgeks . org/composite name-get-method-in-Java-with-examples/ The get() method of a javax.naming.CompositeName class is used to obtain a component of this composite name object. The position passed as a parameter that is used to get the component that appears at that position from the composite name object. Syntax: public String get(int posn) Parameters:This method accepts posn , which is the 0-based index of the component to retrieve. Must be in the range [0, size()]. Return value:This method returns the component at index posn. Exception:If posn is outside the specified range, this method throws ArrayIndexOutOfBoundsException. The following program illustrates the CompositeName.get() method:Program 1: // Java program to demonstrate// CompositeName.get() import java.util.Properties;import javax.naming.CompositeName;import javax.naming.InvalidNameException;public class GFG { public static void main( String[] args) throws InvalidNameException { // create composite name object CompositeName CompositeName1 class=”o”>= new CompositeName( / apply get() String comp1 = CompositeName1.get(0); String comp2 = CompositeName1.get(3); // print value System.out.println(comp1); System.out.println(comp2); }} Output: ax Program 2: // Java program to demonstrate// CompositeName.get() methodimport java.util.Properties;import javax.naming.CompositeName;import javax.naming.InvalidNameException;public class GFG { public static void main(String[] args) throws InvalidNameException { // create composite name object CompositeName CompositeName1 = new CompositeName( “c/e/d/v/a/b/z/y/x/f”); // apply get() String pos3 = CompositeName1.get(3); String pos4 = CompositeName1.get(4); // print value System.out.println( “Component at position 3: ” + pos3); System.out.println( “Component at position 4:…
Property isEmpty() method in Java, example
Properties isEmpty() method in Java, examples Original text: https://www . geesforgeks . org/properties-isempty-method-in-Java-with-examples/ The isEmpty() method of the property class is used to check whether the property object is empty. Syntax: public boolean isEmpty() Parameters:This method does not accept parameters Returns:This method returns a Boolean value indicating whether the attribute object is null. The following program shows the implementation of the int isEmpty() method. Program 1: // Java code to show the implementation of// isEmpty methodimport java. util.*;public class GfG { // Main method public static void main(String[] args) { // Create a properties and add some values Properties properties = new Properties(); properties .put(“Pen”, 10); properties.put(“Book”, 500); properties.put (“Clothes”, 400 ); properties.put(“Mobile”, 5000); // Print Properties details System.out.println(“Properties: ” class=”o”>+ properties.toString ()); // Checking if the Properties is empty System.out.println(“Is Properties empty: ” properties.isEmpty()); }} Output: Properties: {Book=500, Mobile=5000, Pen=10, Clothes=400}Is Properties empty: false Program 2: // Java program to demonstrate// isEmpty() method.import java.util.*;public class GFG { // Main method public static void main(String[] args) { // Create a properties and add some values Properties properties = new Properties(); // Print Properties details System.out.println(“Current Properties: ” =”p”>.toString()); // Checking if the Properties is empty System.out .println(“Is Properties empty: ” /span>isEmpty()); }} Output: Current Properties: {}Is Properties empty: true Reference: https://docs . Oracle . com/javase/9/docs/API/Java/util/properties .…