Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字符串的逐字符读取问题:JAVA_Java - Fatal编程技术网

字符串的逐字符读取问题:JAVA

字符串的逐字符读取问题:JAVA,java,Java,我有一个很长的字符串,我想逐字读取,直到字符串结束 在Java中,我找到了两种阅读方法: 使用CharAt 使用StringReader 有人能帮我吗 哪条路更快 如何使用StringReader逐字读取直到结束 绳子的长度 提前谢谢 量一量就知道了!说真的,我的硬件和你的硬件可能不一样。但我怀疑charAt() 它只是一个读取器,因此它与任何其他读取器具有相同的方法,包括int read(),它将逐个返回每个字符的Unicode码点 量一量就知道了!说真的,我的硬件和你的硬件可能不一样。但我怀

我有一个很长的字符串,我想逐字读取,直到字符串结束

在Java中,我找到了两种阅读方法:

  • 使用CharAt
  • 使用StringReader
  • 有人能帮我吗

  • 哪条路更快
  • 如何使用StringReader逐字读取直到结束 绳子的长度
  • 提前谢谢

  • 量一量就知道了!说真的,我的硬件和你的硬件可能不一样。但我怀疑
    charAt()
  • 它只是一个
    读取器
    ,因此它与任何其他
    读取器
    具有相同的方法,包括
    int read()
    ,它将逐个返回每个字符的Unicode码点
  • 量一量就知道了!说真的,我的硬件和你的硬件可能不一样。但我怀疑
    charAt()
  • 它只是一个
    读取器
    ,因此它与任何其他
    读取器
    具有相同的方法,包括
    int read()
    ,它将逐个返回每个字符的Unicode码点
  • 你自己量一下。一旦字符串加载到内存中,我就看不出有什么有意义的区别
  • (RFTD)
  • 你自己量一下。一旦字符串加载到内存中,我就看不出有什么有意义的区别
  • (RFTD)
  • “很长”是多长

    使用toCharArray()方法将字符串转换为char数组,并从循环中获取:

    字符串mystring=“test”

    char[]myCharArray=mystring.toCharArray()

    多长是“很长?”

    使用toCharArray()方法将字符串转换为char数组,并从循环中获取:

    字符串mystring=“test”


    char[]myCharArray=mystring.toCharArray()

    下面是一个简单的类,它是根据您的要求设计的,使用charAt方法:

    public class Test {
    
    static String tS = "Hello this is a string";
    
    
    public static void main (String args []) {
    //make a blank character that gets replaced each time the for loop runs     
    char c;     
        for (int j = 0; j < tS.length(); j++) {
                //for loop runs up the length of the string, then sets c to the
                //current character in the string. Printing c just proves the concept.
            c = tS.charAt(j);
            System.out.println(c);
        }
    }
    }
    
    公共类测试{
    静态字符串tS=“您好,这是一个字符串”;
    公共静态void main(字符串参数[]){
    //创建一个空白字符,该字符在每次for循环运行时被替换
    字符c;
    对于(int j=0;j

    请记住,这些都不需要在类或主方法中完成——您可以在代码中需要的任何地方完成

    下面是一个简单的类,它是根据您的要求设计的,使用charAt方法:

    public class Test {
    
    static String tS = "Hello this is a string";
    
    
    public static void main (String args []) {
    //make a blank character that gets replaced each time the for loop runs     
    char c;     
        for (int j = 0; j < tS.length(); j++) {
                //for loop runs up the length of the string, then sets c to the
                //current character in the string. Printing c just proves the concept.
            c = tS.charAt(j);
            System.out.println(c);
        }
    }
    }
    
    公共类测试{
    静态字符串tS=“您好,这是一个字符串”;
    公共静态void main(字符串参数[]){
    //创建一个空白字符,该字符在每次for循环运行时被替换
    字符c;
    对于(int j=0;j

    请记住,这些都不需要在类或主方法中完成——您可以在代码中需要的任何地方完成

    这并不能回答OP提出的任何一个问题。他想“一个字符一个字符地读,直到字符串结束。”然后他说,在Java中,他找到了两种读的方法,我给他提供了第三种可能有效的方法。如果你需要更具说服力的话,我不是在胡扯:这并不能回答OP提出的任何一个问题。他想“一个字符一个字符地读到字符串的末尾。”然后他说,在Java中,他找到了两种读的方法,我给他提供了第三种可能有效的方法。如果你需要更令人信服的话,我不会说:谢谢。但是你为什么怀疑?有什么具体的原因吗?谢谢。但是你为什么怀疑?有什么具体的原因吗?