• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

subString method in String class

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the first variant, endpos is taken to be the end of the given string.

_steve.
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first simply is a convenient method.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Jim. It must be substring() method. It was a costly mistake.
 
reply
    Bookmark Topic Watch Topic
  • New Topic