📌  相关文章
📜  Java中的 CharArrayReader markSupported() 方法及示例

📅  最后修改于: 2022-05-13 01:55:49.287000             🧑  作者: Mango

Java中的 CharArrayReader markSupported() 方法及示例

Java中CharArrayReader类的markSupported()方法用来检查这个CharArrayReader是否支持mark()操作。它返回一个布尔值,说明阅读器是否支持标记。

句法:

public boolean markSupported()

参数:此方法不接受任何参数

返回值:此方法返回一个布尔值,该值告诉该 CharArrayReader 是否支持 mark() 操作。如果是 markSupported,则返回 true。否则返回false。

以下方法说明了 markSupported() 方法的工作原理:

方案一:

// Java program to demonstrate
// CharArrayReader markSupported() method
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            char[] str = { 'G', 'e', 'e', 'k', 's',
                           'F', 'o', 'r',
                           'G', 'e', 'e', 'k', 's' };
  
            // Create a CharArrayReader instance
            CharArrayReader reader
                = new CharArrayReader(str);
  
            // Check if the CharArrayReader is
            // markSupported using markSupported()
            System.out.println("Is CharArrayReader markSupported: "
                               + reader.markSupported());
  
            reader.close();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
输出:
Is CharArrayReader markSupported: true

方案二:

// Java program to demonstrate
// CharArrayReader markSupported() method
  
import java.io.*;
import java.util.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
            char[] str = { 'G', 'E', 'E', 'K', 'S' };
  
            // Create a CharArrayReader instance
            CharArrayReader reader
                = new CharArrayReader(str);
  
            // Check if the CharArrayReader is
            // markSupported using markSupported()
            System.out.println("Is CharArrayReader markSupported: "
                               + reader.markSupported());
  
            reader.close();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
输出:
Is CharArrayReader markSupported: true

参考: https://docs.oracle.com/javase/9/docs/api/ Java/io/CharArrayReader.html#markSupported–