• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Insert into String

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
Thanks.

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
http://www.geocities.com/mjbruesch
 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Mike.
reply
    Bookmark Topic Watch Topic
  • New Topic