Thread View: borland.public.jbuilder.java.language
2 messages
2 total messages
Started by apostolish
Tue, 16 Aug 2005 13:01
copy string to string
Author: apostolish
Date: Tue, 16 Aug 2005 13:01
Date: Tue, 16 Aug 2005 13:01
12 lines
1227 bytes
1227 bytes
Hello, my problem is:
String str1 = new String(" "); // length 20
String str2 = new String("test"); // length 4
Which is the fastest way to copy str2 to str1 from postion 10 ?
(for example: str1 = " test ")
Thanks in advance,
Apostolis
Hatziyannis
Re: copy string to string
Author: Lori M Olson [TeamB]
Date: Tue, 16 Aug 2005 18:13
Date: Tue, 16 Aug 2005 18:13
41 lines
2160 bytes
2160 bytes
apostolish wrote:
> Hello, my problem is:
>
>
> String str1 = new String(" "); // length 20
> String str2 = new String("test"); // length 4
>
> Which is the fastest way to copy str2 to str1 from postion 10 ?
> (for example: str1 = " test ")
>
> Thanks in advance,
> Apostolis
> Hatziyannis
>
>
Just to be completely clear... Strings are immutable, so what you are
attempting to do is not altering str1, but creating a new String (which
can be assigned to str1 if you want) with the desired contents.
Look at the API for String, and for StringBuffer. If you are using JDK
5, then also look at StringBuilder.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads