Replicating String.split with StringTokenizer

后端 未结 9 1251
心在旅途
心在旅途 2021-02-06 14:03

Encouraged by this, and the fact I have billions of string to parse, I tried to modify my code to accept StringTokenizer instead of String[]

The only t

9条回答
  •  花落未央
    2021-02-06 14:55

    You could do something like that. It's not perfect, but it might be working for you.

    public static List find(String test, char c) {
        List list = new Vector();
        start;
        int i=0;
        while (i<=test.length()) {
            int start = i;
            while (i

    If possible you can ommit the List thing and directly do something to the substring:

    public static void split(String test, char c) {
        int i=0;
        while (i<=test.length()) {
            int start = i;
            while (i

    On my System the last method is faster than the StringTokenizer-solution, but you might want to test how it works for you. (Of course you could make this method a little shorter by ommiting the {} of the second while look and of course you could use a for-loop instead of the outer while-loop and including the last i++ into that, but I didn't do that here because I consider that bad style.

提交回复
热议问题