S
sara
Hi All,
Thanks a lot for your responses. I found all of them very usefull.
Thanks a lot for your responses. I found all of them very usefull.
Javier said:Jeffrey Schwab ha escrito:
Then you'd better use StringBuffer instead:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html
and having the code \0000 to delimit the valid content of a buffer is
not always a good idea.
There may be valid content beyond that.
Javier said:Jeffrey Schwab ha escrito:
Then you'd better use StringBuffer instead:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html
and having the code \0000 to delimit the valid content of a buffer is
not always a good idea.
Agreed. In fact, it's rarely a good idea in Java. But that doesn't
mean it can't be done, and in fact there might even be real situations
where it's useful. You might want to review the earlier parts of this
thread, especially the part you snipped.
There may be valid content beyond that.
Eh? No, by definition, it cannot. We've specifically defined the
buffer to *not* have valid content beyond the null character. That is
the meaning of null in this context. If a given source of input can
produce valid, zero-valued characters, they must be escaped for the
delimeter to be meaningful.
Here's a good example of the same technique being used as part of the
interface to ArrayList:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html#toArray(T[])
"If the list fits in the specified array with room to spare (i.e., the
array has more elements than the list), the element in the array
immediately following the end of the collection is set to null. This is
useful in determining the length of the list only if the caller knows
that the list does not contain any null elements."
Javier said:Jeffrey Schwab ha escrito:
Agreed. In fact, it's rarely a good idea in Java. But that doesn'tJavier said:Jeffrey Schwab ha escrito:
Remember that arrays in Java _also_ have the length attribute.
That's not the same thing. What's of interest here is not the size of
the buffer, but the amount of valid content it contains.
Then you'd better use StringBuffer instead:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html
and having the code \0000 to delimit the valid content of a buffer is
not always a good idea.
mean it can't be done, and in fact there might even be real situations
where it's useful. You might want to review the earlier parts of this
thread, especially the part you snipped.
Eh? No, by definition, it cannot. We've specifically defined theThere may be valid content beyond that.
buffer to *not* have valid content beyond the null character. That is
the meaning of null in this context. If a given source of input can
produce valid, zero-valued characters, they must be escaped for the
delimeter to be meaningful.
Here's a good example of the same technique being used as part of the
interface to ArrayList:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html#toArray(T[])
"If the list fits in the specified array with room to spare (i.e., the
array has more elements than the list), the element in the array
immediately following the end of the collection is set to null. This is
useful in determining the length of the list only if the caller knows
that the list does not contain any null elements."
Sorry if I was not clear. I agree with you in that in some case is
usefull. I meant that there are times in which \u0000 might be
considered a valid character, for example not for limiting the end of
the buffer, but the end of a chunk or something similar. Even sometimes
could be just ignored. Or even it might be a part of some kind of
encription, etc.
According to the text you quote, ArrayList implements null, which I
believe is not the same as \u0000 (correct me if I'm wrong).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.