jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Insert into String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Insert into String" Watch "Insert into String" New topic

Insert into String

sabbir kazi
Ranch Hand

Joined: Feb 03, 2001
Posts: 62
How to insert a substring into the string in Java? Like:
String One = "My is Sabbir"
String Two = "name";
So, after inserting "String Two" into "String One", the new "String One" will be -> "My name is Sabbir".

Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
First of all, those are string literals you're using. Secondly, even if you created an object using the String constructor, you cannot insert characters into a String object, you'd have to create a new String object. You can use the StringBuffer class however to insert characters or even another String into the StringBuffer object. Example:

The previous program will print "My name is Mike." and the original object was still used, only changed.
Hope that's clear...

Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.

Michael J Bruesch<br /><i>I code, therefore I am.</i>
sabbir kazi
Ranch Hand

Joined: Feb 03, 2001
Posts: 62
Thanks, Mike.
I agree. Here's the link: http://aspose.com/file-tools
subject: Insert into String
It's not a secret anymore!