using insertAt method in java

insertAt to manipulate String data

Page 1 of 1

6 Replies - 6814 Views - Last Post: 04 March 2008 - 09:26 AM Rate Topic: -----

#1 Mideval1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

using insertAt method in java

Post icon  Posted 04 March 2008 - 06:04 AM

I'm trying to use the insertAt method to manipulate String Data using a StringBuffer but I keep getting an error that insertAt is an unrecognized method. Anybody know what I'm doing wrong here?




String strA = "Hello There" ;//initial string value

StringBuffer strBuffer = new StringBuffer(strA);

strBuffer.insertAt(0,"World!");
Is This A Good Question/Topic? 0
  • +

Replies To: using insertAt method in java

#2 bhandari   User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 754
  • Joined: 31-January 08

Re: using insertAt method in java

Posted 04 March 2008 - 06:10 AM

its simply

public synchronized StringBuffer insert(int offset, Object obj)


Was This Post Helpful? 0
  • +
  • -

#3 Mideval1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

Re: using insertAt method in java

Posted 04 March 2008 - 06:43 AM

View Postbhandari, on 4 Mar, 2008 - 06:10 AM, said:

its simply

public synchronized StringBuffer insert(int offset, Object obj)





I still get the same error. its the insertAt method that is causing me all the headache. It should be in the java.lang.String Class but java can't import it for some reason. Any ideas?
Was This Post Helpful? 0
  • +
  • -

#4 bhandari   User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 754
  • Joined: 31-January 08

Re: using insertAt method in java

Posted 04 March 2008 - 06:46 AM

If i was not clear, its insert and not insertAt
Was This Post Helpful? 0
  • +
  • -

#5 Mideval1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

Re: using insertAt method in java

Posted 04 March 2008 - 06:50 AM

View Postbhandari, on 4 Mar, 2008 - 06:46 AM, said:

If i was not clear, its insert and not insertAt



Thanks Bhandari! It works now, the program required insertAt but the method doesn't exist apparently in my java class library, insert is working. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#6 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: using insertAt method in java

Posted 04 March 2008 - 06:53 AM

Please read the explanation of the methods on the JavaDoc website, about StringBuffer and insert.

There is no method called insertAt(int, String) there is only charAt(int), deleteCharAt(int) and setCharAt(int, char) . :)

This post has been edited by letthecolorsrumble: 04 March 2008 - 06:55 AM

Was This Post Helpful? 0
  • +
  • -

#7 bhandari   User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 754
  • Joined: 31-January 08

Re: using insertAt method in java

Posted 04 March 2008 - 09:26 AM

welcome Mideval1. To come back in case of any problem here and spread the word </DIC>
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1