字符串的逐字符读取问题:JAVA
我有一个很长的字符串,我想逐字读取,直到字符串结束 在Java中,我找到了两种阅读方法:字符串的逐字符读取问题:JAVA,java,Java,我有一个很长的字符串,我想逐字读取,直到字符串结束 在Java中,我找到了两种阅读方法: 使用CharAt 使用StringReader 有人能帮我吗 哪条路更快 如何使用StringReader逐字读取直到结束 绳子的长度 提前谢谢 量一量就知道了!说真的,我的硬件和你的硬件可能不一样。但我怀疑charAt() 它只是一个读取器,因此它与任何其他读取器具有相同的方法,包括int read(),它将逐个返回每个字符的Unicode码点 量一量就知道了!说真的,我的硬件和你的硬件可能不一样。但我怀
charAt()
读取器
,因此它与任何其他读取器
具有相同的方法,包括int read()
,它将逐个返回每个字符的Unicode码点charAt()
读取器
,因此它与任何其他读取器
具有相同的方法,包括int read()
,它将逐个返回每个字符的Unicode码点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中,他找到了两种读的方法,我给他提供了第三种可能有效的方法。如果你需要更令人信服的话,我不会说:谢谢。但是你为什么怀疑?有什么具体的原因吗?谢谢。但是你为什么怀疑?有什么具体的原因吗?