【发布时间】:2013-02-15 19:03:00
【问题描述】:
正如问题所述,给出以下代码:
public class Foo
{
public static void main(String[] args)
{
String test = "Cats go meow";
String[] tokens = test.split(" ");
}
}
是否可以按照以下方式在 split 函数中预编译该正则表达式:
public class Foo
{
Pattern pattern = Pattern.compile(" ");
public static void main(String[] args)
{
String test = "Cats go meow";
String[] tokens = test.split(pattern);
}
}
【问题讨论】:
-
split(" ") 更快(见下方评论)
-
@michael_s 我加了评论,请反击。
标签: java regex performance