This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StringIndexOut OfBoundsException

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error "StringIndexOutOfBoundsException" when my input string is st= "Hold State,0,0,0,0,0,0,0,0"

The code below shows what I'm trying to do, create a StingBuffer os size 8 from the input



any ideas?
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the constructor of StringBuffer that takes an int parameter, it does not create a StringBuffer with that many characters. It creates a StringBuffer with that capacity.

The StringBuffer will have no characters in it.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikos,

Are you trying to split obtained the contents of the comma-delimited String? Read the Java API and you'd notice that StringTokenizer is not recommended for usage anymore, except in supporting legacy codes.

As of JDK 1.4 and later, you could use the split method of String class.



This way, your codes is easier to maintain & understand. There's also performance gain involved, if I'm not mistaken.
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it was helpful

it now works


cheers
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic