0 Replies - 701 Views - Last Post: 27 July 2017 - 06:48 PM

#1 Vette   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 15-April 17

String.startsWith() - Why Does it Not Accept a Char?

Posted 27 July 2017 - 06:48 PM


In a Java textbook I purchased, it was noted that the the startsWith() and endsWith() methods accept only Strings, not char, values. As, to my knowledge, many methods, such as indexOf() and replace() are capable of accepting both chars and Strings, I found this interesting. From my (very limited) understanding of how the String class is implemented, this would not be a difficult task, nor do I think it is illogical to assume a user may wish to determine if a String begins or ends with a single char. I realize this does not hurt the practicality of the class in the real-world, but I am studying for my OCA exam, and could see this concept coming up. Any ideas why the startsWith() and endsWith() methods are not overloaded?

More of a curious question than anything. :)

Is This A Good Question/Topic? 0
  • +

Page 1 of 1