• Post Reply Bookmark Topic Watch Topic
  • New Topic

Alternate Replacement of ParseInt in java ?  RSS feed

 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implementation of parseInt() methods in java..

i don't want to use this method and also as the code written in Integer class of Lang package is much harder to understand.

so is it possible to write simple code for replacement of ParseInt() method..

like

int myOwnParseInt(String args) {

// i want the implementation of of parseInt

}
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prabhat Ranjan wrote:
i don't want to use this method and also as the code written in Integer class of Lang package is much harder to understand.

Well, you could mention the part that you didn't understand and people here will try to help you with it.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to rewrite something that has been working just fine for over a decade?

That said, it's not really hard to write a simple parse method:
This quick code has a few flaws:
- there is no checking on empty strings, or only sign symbols
- there is no overflow checking
- there is no check if each character is a digit

That shouldn't be too hard to add though.
 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks ! i will test this code !
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prabhat Ranjan wrote:i don't want to use this method and also as the code written in Integer class of Lang package is much harder to understand.

There's probably a *lot* of code in the JDK that's hard to understand--why not just view them as black boxes? Why does it matter that code you almost never look at is difficult to understand?

If you just *want* to write your own versions of code that already works, that's one thing (although a relatively low return on investment--if my boss caught me re-writing JDK code I'd be in trouble).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!