Java 如何在固定字符序列上拆分字符串?

Java 如何在固定字符序列上拆分字符串?,java,string,split,Java,String,Split,假设我有以下字符串: String asd = "this is test ass this is test" 我想用“ass”字符序列分割字符串 我用过: asd.split("ass"); 它不起作用。我需要做什么?这对我来说似乎很好: public class Test { public static void main(String[] args) { String asd = "this is test ass this is test";

假设我有以下字符串:

String asd = "this is test ass this is test"
我想用“ass”字符序列分割字符串

我用过:

asd.split("ass");

它不起作用。我需要做什么?

这对我来说似乎很好:

public class Test
{
    public static void main(String[] args) {
        String asd = "this is test ass this is test";
        String[] bits = asd.split("ass");
        for (String bit : bits) {
            System.out.println("'" + bit + "'");
        }
    }
}
结果:

'this is test '
' this is test'
你真正的分隔符可能不同吗?别忘了split将其参数用作正则表达式

public class Splitter {

    public static void main(final String[] args) {
        final String asd = "this is test ass this is test";
        final String[] parts = asd.split("ass");
        for (final String part : parts) {
            System.out.println(part);
        }
    }
}
印刷品:

this is test 
 this is test
在Java6下。你期望的产出是什么

String asd = "this is test foo this is test";
String[] parts = asd.split("foo");
试试这个,它会起作用的。

我会用
“这是测试foo这是测试”
作为例子:)