【发布时间】:2011-12-17 15:54:44
【问题描述】:
我准备了一个简单的代码 sn-p 以便将错误部分与我的 Web 应用程序分开。
public class Main {
public static void main(String[] args) throws IOException {
System.out.print("\nEnter a string:->");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String temp = br.readLine();
String words[] = temp.split(".");
for (int i = 0; i < words.length; i++) {
System.out.println(words[i] + "\n");
}
}
}
我在构建 Web 应用程序 JSF 时对其进行了测试。我只想知道为什么上面的代码temp.split(".") 不起作用。声明,
System.out.println(words[i]+"\n");
在控制台上不显示任何内容意味着它没有通过循环。当我将 temp.split() 方法的参数更改为其他字符时,它像往常一样工作得很好。可能是什么问题?
【问题讨论】:
-
逃脱它。拆分适用于正则表达式
-
哎呀,它默认是Java中的正则表达式?