aspose file tools*
The moose likes Beginning Java and the fly likes Can you explain this code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can you explain this code?" Watch "Can you explain this code?" New topic
Author

Can you explain this code?

shoeb sayyed
Ranch Hand

Joined: Mar 14, 2010
Posts: 48



in the //////////////SOME CODE of i write this


STILL NOTHING IS REPLACED? What happens exactly?


Thanks,
Shoeb
Baiju Scariah
Ranch Hand

Joined: Mar 17, 2005
Posts: 33
In Java String is immutable - meaning not modifiable. You may modify the String reference and store a new string there.

Ex:
Modify StringReplace() as give below..

public static String StringReplace(String t)
{
t=t.replace("j","i"); //It should have replaced "j" from "java" with an "i"
return t;
}

and

in main() as given below

s = StringReplace(s); //what happens over here?

This would give you desired result.
shoeb sayyed
Ranch Hand

Joined: Mar 14, 2010
Posts: 48
thanks Baiju,

I understood. That was a perfect answer

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14107
    
  16

Also, variables are passed by value in Java. Assigning another value to t in line 6 and 12 has no effect.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
jQuery in Action, 2nd edition
 
subject: Can you explain this code?