Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 3 Important StringBuilder Methods p114

 
Michael Marr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under the heading 'charAt(), indexOf(), length(), and substring()' it states that:

"These four methods work exactly the same as in the String class.".

However I've noticed from running the subsequent 5 lines of code that indexOf(char ch) does not compile with the StringBuilder class. In other words you can't pass a character as a parameter to 'indexOf), it will only compile, with the StringBuilder class, if you pass it a string.

So, the line:will not compile if it is written as...ie if you substitute the character 'a' for the string "a" in the first occurence of sb.indexOf()



 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi michael marr,

First of all, a warm welcome to CodeRanch!

michael marr wrote:"These four methods work exactly the same as in the String class.".

However I've noticed from running the subsequent 5 lines of code that indexOf(char ch) does not compile with the StringBuilder class. In other words you can't pass a character as a parameter to 'indexOf), it will only compile, with the StringBuilder class, if you pass it a string.

In this topic the same quote from the study guide is already discussed. Definitely worth reading!

Hope it helps!
Kind regards,
Roel

PS. Always use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers. I already added the code tags for you. See how much easier the code is to read?
 
Michael Marr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, sorry about no code tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic