String Tokenizer issue

2019-09-17 04:54发布

AM using string tokenizer to delimit the string response by ^

12/30/2011 12:00:00 AM^President^^^159^True^True^True^True^True^False^False^True^True^3/18/2011 12:00:00 AM^True^Jujama, Inc.^^^^True^True

but the problem is when ^ delimiter consecutively its skipping that one and adding in to array. But i want to add space if two ^delimiters comes.

How to do that?

My code is:

 StringTokenizer tokens = new StringTokenizer(partId, "^");

              while(tokens.hasMoreTokens()){

                 String value=tokens.nextToken();
                 userValues.add(value);
                 System.out.println("..."+value);

              }   

2条回答
你好瞎i
2楼-- · 2019-09-17 05:34

User string.split("^") instead. Split receives regex, so you can do almost what you want within one line.

查看更多
登录 后发表回答