How to insert a date variable in java?

How do you insert one String into another in Java?

  • I know how to do it in Visual C# but I have to compare that language to Java, and I have absolutely no idea how to do it. Can you do it using Strings or do you have to use StringBuffers? Please let me know how to insert one String into another in Java, if there is a way to do so. Thanks in advance for all your answers. :)

  • Answer:

    I'm not quite sure I understand, but I'll try. Putting one String into another isn't all that hard. Psuedocode below: String blah, wah; blah = ("Wahwahwah"); wah = blah; If you're asking about actually smooshing two different Strings together, it's not much harder. String blwhah = (blah + wah); I think that covers it. EDIT: Sent an email back to you, but here it is here. First, create a StringBuffer, that is: StringBuffer s1 = new StringBuffer("I am right now."); Then, use the insert method, that is: s1.insert(3, "happy "); Where 3 is the place the string will be put and "happy " (note the space) is the string to be added. Hope that helps.

promise at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Use the string concat method to join the to strings, if that is what you mean. Other than that you could use the string buffers, but for something simple like this just use the string methods provided. Check http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html for the string methods

Nick P

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.