Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > End of String

Reply
Thread Tools

End of String

 
 
sara
Guest
Posts: n/a
 
      09-26-2006
Hi All,

Thanks a lot for your responses. I found all of them very usefull.
Oliver Wong wrote:
> "Javier" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> >
> > 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/...ingBuffer.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.

>
> The context of the thread was emulating C's behaviour. The closest thing
> to having pointings to arbitrary contiguous regions of memory in Java is
> allocating an array, and C uses \u0000 to delimit the end of Strings.
>
> - Oliver


 
Reply With Quote
 
 
 
 
Jeffrey Schwab
Guest
Posts: n/a
 
      09-27-2006
Javier wrote:
> 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/...ingBuffer.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/...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."
 
Reply With Quote
 
 
 
 
Javier
Guest
Posts: n/a
 
      09-28-2006

Jeffrey Schwab ha escrito:

> Javier wrote:
> > 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/...ingBuffer.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/...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).

 
Reply With Quote
 
Jeffrey Schwab
Guest
Posts: n/a
 
      09-28-2006
Javier wrote:
> Jeffrey Schwab ha escrito:
>
>> Javier wrote:
>>> 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/...ingBuffer.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/...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.


Right, the value zero (0) has other uses than being a delimiter.

> According to the text you quote, ArrayList implements null, which I
> believe is not the same as \u0000 (correct me if I'm wrong).


You are again correct '\u0000' is the null character value, not the null
reference. ArrayList uses a null reference, because Lists hold
references, not primitive chars.
 
Reply With Quote
 
neo neo is offline
Junior Member
Join Date: Aug 2011
Posts: 1
 
      08-21-2011
please help me!!
check it for me. thank!


import java.lang.*;
import java.util.*;
public class bai5_2 {
public static void timkiem()
{
Scanner nhapvao=new Scanner(System.in);
System.out.println(" String :");
String str1=new String();
str1=nhapvao.nextLine();
int n=str1.length();
int i,dem,m;i=0;
dem=i;

System.out.print(str1);
i=0;
while(i<n)
{
if(str1.charAt(i)==' '){while(str1.charAt(i)==' ') i++; }
else {dem++;while(str1.charAt(i)!=' ') i++;}
}
System.out.println(dem);

}
public static void main(String args[]){
timkiem();
}



}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to match string end for a multiline string? Peng Yu Perl Misc 2 06-24-2008 02:32 AM
Help with switch configuration, ( 3 3550's, 5 2950's end to end ) ec Cisco 3 07-25-2006 10:30 AM
String Gets Truncated: VBScript End of String Character? Mike ASP General 1 08-25-2005 02:50 PM
Measure delay end-to-end Dave Cisco 1 07-20-2004 12:51 PM
is there a difference between CIR and CIR+end to end clear channel connection? ike lozada Cisco 0 05-27-2004 02:34 AM



Advertisments