Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PushbackReader markSupported() method in Java with Examples

  • Last Updated : 29 Apr, 2019

The markSupported() method of PushbackReader Class in Java is used to check whether this PushbackReader is supports mark() operation or not. It returns a boolean which states if the reader is mark supported.

Syntax:

public boolean markSupported()

Parameters: This method does not accepts any parameters

Return Value: This method returns a boolean value which tells if this PushbackReader supports mark() operation or not. It return true if it is markSupported. Else it returns false.

Below methods illustrates the working of markSupported() method:

Program 1:




// Java program to demonstrate
// PushbackReader markSupported() method
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
            // Initializing a StringReader
            // and PushbackReader
            String s = "GeeksForGeeks";
  
            StringReader stringReader
                = new StringReader(s);
            PushbackReader pushbackReader
                = new PushbackReader(stringReader);
  
            // check if the mark() method
            // is supported or not
            System.out.println("Is mark() supported:"
                               + pushbackReader.markSupported());
  
            // Close the stream using markSupported()
            pushbackReader.close();
            System.out.println("Stream Closed.");
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Output:
Is mark() supported:false
Stream Closed.

Program 2:




// Java program to demonstrate
// PushbackReader markSupported() method
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
            // Initializing a StringReader
            // and PushbackReader
            String s = "GFG";
  
            StringReader stringReader
                = new StringReader(s);
            PushbackReader pushbackReader
                = new PushbackReader(stringReader);
  
            // check if the mark() method
            // is supported or not
            System.out.println("Is mark() supported:"
                               + pushbackReader.markSupported());
  
            // Close the stream
            pushbackReader.close();
            System.out.println("Stream Closed.");
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Output:
Is mark() supported:false
Stream Closed.

Reference: https://docs.oracle.com/javase/9/docs/api/java/io/PushbackReader.html#markSupported–


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!