Replacing Strings

Hi,from the javadoc...i was able to se ethat characters of a particular string can be replaced....but is it possbile to replace entire string?for eg " a jumbo jet is flying" ...in this sentence is it possible to replace jet with null or no string?Thanksvivek
[293 byte] By [vivek.shankara] at [2007-10-2 5:46:38]
# 1
You can't replace it with null. You can replace it with zero or more characters.See String's replaceAll and reaplaceFirst methods. Note that strings are immutable, so you'll have to use the new string that's returned from those methods.
targaryena at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 2
why would you want to do that? remember Strings are immutable anytime a similar operation is carried out a ew object is created. Thats not a good practice.
kilyasa at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 3

> is it possible to replace jet with null or no string?

While you can't directly modify that String, you can certainly create a new String that contains what you want.

It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of [url=http://java.sun.com/reference/api/index.html]documentation[/url] that you can even [url=http://java.sun.com/docs/index.html]download[/url] for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.

[url=http://java.sun.com/reference/api/index.html]Java?API Specifications[/url]

[url=http://java.sun.com/j2se/1.5.0/docs/api/]Java?1.5 JDK Javadocs[/url]

yawmarka at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 4
Okie thanks...i jus thoght i hav to create a sepearet function to do this operation...ijus wanted to check if java provided any method to replace string like it is used to replace characters.....Thanks!vivek
vivek.shankara at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 5
SINCE STRINGS are immutable...does a new string gets create when using "replace" function provided by string class?Thanksvivek
vivek.shankara at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 6
> SINCE STRINGS are immutable...does a new string gets> create when using "replace" function provided by> string class?> > Thanks> vivekyes. thats why its preferrable to use StringBuffer
kilyasa at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 7
> SINCE STRINGS are immutable...does a new string gets> create when using "replace" function provided by> string class?Re-read these replies and/or the API docs carefully.
targaryena at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...
# 8

> Okie thanks...i jus thoght i hav to create a sepearet

> function to do this operation...ijus wanted to check

> if java provided any method to replace string like it

> is used to replace characters.....

>

What part of the following did you not understand?

It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program...

Once you read the documentation for String, and there are many things in there, you would probably find the following....

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#replaceFirst(java.lang.String,%20java.lang.String)

jschella at 2007-7-16 1:56:24 > top of Java-index,Java Essentials,New To Java...