Forums Register Login

Alternate Replacement of ParseInt in java ?

+Pie Number of slices to send: Send
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

}

 
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Ok thanks ! i will test this code !
+Pie Number of slices to send: Send
 

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).
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3031 times.
Similar Threads
Mouseover popup location
adding numbers
Finding exact element in a javascript variable
How to convert a string to a float or double?
Issue with String replacement
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:42:20.