StringReader reset() method in Java with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The reset() method of StringReader Class in Java is used to reset the stream. After reset, if the stream has been marked, then this method attempts to reposition it at the mark, else it will try to position it to the starting. Syntax: public void reset() Parameters: This method do not accepts any parameter. Return Value: This method do not returns any value. Exception: This method throws IOException: if some error occurs while input output if the stream has not been marked if the mark has been invalidated if the reset() method is not supported. Below methods illustrates the working of reset() method: Program 1: Java // Java program to demonstrate // StringReader reset() method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { String str = "GeeksForGeeks"; // Create a StringReader instance StringReader reader = 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.read(); System.out.print((char)ch); } System.out.println(); // mark the stream for // 5 characters using reset() reader.mark(5); // reset the stream position reader.reset(); // Read the 5 characters from marked position // to this reader using read() method for (int i = 0; i < 5; i++) { ch = reader.read(); System.out.print((char)ch); } } catch (Exception e) { System.out.println(e); } } } Output: GeeksForGe eks?? Program 2: Java // Java program to demonstrate // StringReader reset() method import java.io.*; import java.util.*; class GFG { public static void main(String[] args) { try { String str = "GeeksForGeeks"; // Create a StringReader instance StringReader reader = 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.read(); System.out.print((char)ch); } System.out.println(); // reset the stream position reader.reset(); // Read the 5 characters from marked position // to this reader using read() method for (int i = 0; i < 5; i++) { ch = reader.read(); System.out.print((char)ch); } } catch (Exception e) { System.out.println(e); } } } Output: GeeksForGe Geeks Reference: https://docs.oracle.com/javase/9/docs/api/java/io/StringReader.html#reset-- Comment More infoAdvertise with us Next Article Reader reset() method in Java with Examples C code_r Follow Improve Article Tags : Java Java-Functions Java-IO package Java-StringReader Practice Tags : Java Similar Reads Scanner reset() method in Java with Examples The reset() method of java.util.Scanner class resets this scanner. On resetting a scanner, it discards all of its explicit state information which may have been changed by invocations of useDelimiter(java.util.regex.Pattern), useLocale(java.util.Locale), or useRadix(int). Syntax: public Scanner rese 2 min read String replace() method in Java with Examples The String replace() method returns a new string after replacing all the old characters/CharSequence with a given character/CharSequence. Example:Return a new string where all " o" characters are replaced with "p" character: Java // Java program to demonstrate // the replace() method public class Ma 4 min read StringReader mark(int) method in Java with Examples The mark() method of StringReader Class in Java is used to mark the stream as the checkpoint from where the stream read will start, once reset() is called. This method is not supported by all subclasses of StringReader class. Syntax: public void mark(int readAheadLimit) Parameters: This method accep 3 min read ShortBuffer reset() method in Java with Examples The reset() method of java.nio.ShortBuffer Class is used to reset this buffer's position to the previously-marked position. The mark's value remain unchanged during this process. Syntax: public final ShortBuffer reset() Parameter: This method do not accept any parameter. Return Value: This method re 2 min read Reader reset() method in Java with Examples The reset() method of Reader Class in Java is used to reset the stream. After reset, if the stream has been marked, then this method attempts to reposition it at the mark, else it will try to position it to the starting. Syntax: public void reset() Parameters: This method do not accepts any paramete 3 min read StringWriter flush() method in Java with Examples The flush() method of StringWriter Class in Java is used to flush the writer. By flushing the writer, it means to clear the writer of any element that may be or maybe not inside the writer. It neither accepts any parameter nor returns any value. Syntax: public void flush() Parameters: This method do 2 min read Like