This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can you explain this code?" Watch "Can you explain this code?" New topic

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?

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.

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;


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: 14961

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 8 API documentation
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Can you explain this code?
It's not a secret anymore!