正如问题所述,给出以下代码:
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);
}
}