Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Convert from String Array to String


  • From: gokul.singh@xxxxxxxxx (Gokul Singh)
  • Subject: Convert from String Array to String
  • Date: Tue, 31 Oct 2000 21:24:56 +0530

> > A loop is how you do it.  However, you should _not_ assign to a String
> > reference each time through the loop, as this will create lots of
unneeded
> > String objects.  Instead, use a StringBuffer.  To be even more
> > performance-oriented, don't access the length field every time through,
and
> > try to preallocate the buffer capacity.  Putting that all together:
> ...
> > int length = usernameArr.length;
> > for (int i = 0; i < length; i++)
>
> Is the lookup for array length significant... I thought it was an object
that knew
> it's size... Surely it's not huge... Granted it will be faster, but is it
significant?

I think the advantage here will be due to the fact that the StringBuffer
will not have to reallocate the char[] internally to accomodate the appended
strings. If the initial estimate is correct, then only one allocation may
suffice.

I think the size of an array is an attibute of the array. Am I correct here?
So finding the size of an array will be like reading a member variable and
have no other overheads.

Please correct me if I am wrong in my understanding.


> --
> Aaron Scott-Boddendijk
> INTAZ Limited
> +64 7 838 3371 Voice
> +64 7 838 3372 Fax

Regds,
Gokul



---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx