• Post Reply Bookmark Topic Watch Topic
  • New Topic

subString method in String class  RSS feed

 
Periakaruppan Thiagarajan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overloaded subString method of String class.
1. public String subString(int pos);
2. public String subString(int startpos,int endpos);

Since we could get the results by using the 2nd overloaded subString() method, why sun java provided us the 1st method?. Under what situation, do we intended to use the 1st one?
 
Steve Simon Joseph Fernandez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first variant, endpos is taken to be the end of the given string.

_steve.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Periakaruppan Thiagarajan:
Since we could get the results by using the 2nd overloaded subString() method, why sun java provided us the 1st method?. [/QB]


Just to make life easier for programmers.

Have a look at the API. You can see tons of such cases. It's for our convenience.
[ July 28, 2005: Message edited by: Mani Ram ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first simply is a convenient method.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's also worth noting that there is no "subString" method in the String class. Capitalization is important in Java, and if you don't pay careful attention to it, errors will occur.
[ July 28, 2005: Message edited by: Jim Yingst ]
 
Periakaruppan Thiagarajan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Jim. It must be substring() method. It was a costly mistake.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!