Tokenizing StringBuffer

Is there a way to tokenize StringBuffer, without converting it into toString(). I heard that StringBuffer's toString() does a lazy copy. So, tokenizing will be inefficient when the StringBuffer holds huge data, since you have to call its toString before tokenizing.
[273 byte] By [k2rthika] at [2007-11-26 18:31:43]
# 1
Use glass to cut diamond ?<String> != <StringBuffer>
AbiSSa at 2007-7-9 6:05:51 > top of Java-index,Java Essentials,Java Programming...
# 2
I don see why you would want to put string into a stringBuffer and then tokenize it again. The better way will be to use array list.
AbiSSa at 2007-7-9 6:05:51 > top of Java-index,Java Essentials,Java Programming...
# 3

> Is there a way to tokenize StringBuffer, without

> converting it into toString(). I heard that

> StringBuffer's toString() does a lazy copy. So,

> tokenizing will be inefficient when the StringBuffer

> holds huge data, since you have to call its toString

> before tokenizing.

you can use these methods at StringBuffer if you don't use StringTokenizer

1. indexOf - find index for specific delimeter or tokenizer

2. substring - split the result

p_epia at 2007-7-9 6:05:51 > top of Java-index,Java Essentials,Java Programming...
# 4

Instead of StringTokenizer, you can probably use the Pattern and Matcher classes. They'll work with StringBuffer directly, because it implements CharSequence. Avoid the split() methods, and use the group() methods sparingly, and you should be able to keep the number of String objects to a minimum.

http://java.sun.com/docs/books/tutorial/essential/regex/index.html

uncle_alicea at 2007-7-9 6:05:51 > top of Java-index,Java Essentials,Java Programming...