tag:blogger.com,1999:blog-8712770457197348465.post1060282119017927395..comments2024-03-18T23:01:42.768-07:00Comments on Javarevisited: Difference between valueOf and parseInt method in Java? Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8712770457197348465.post-10765563369594889512013-04-28T01:44:17.301-07:002013-04-28T01:44:17.301-07:00@Javin gr8 article , it has clearly explain the co...@Javin gr8 article , it has clearly explain the concepts ...Actually, valueOf uses parseInt internally. The difference is parseInt returns an int primitive while valueOf returns an Integer object. Consider from the Integer.class source:<br /><br />public static int parseInt(String s) throws NumberFormatException {<br />return parseInt(s,10);<br />}<br /><br />public static Integer valueOf(String SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61527511513980772013-04-26T07:23:02.845-07:002013-04-26T07:23:02.845-07:00@Daniel, I don't know the exact reason, but tw...@Daniel, I don't know the exact reason, but two observation make sense :<br /><br />1) Those are most frequently used numbers, so it make sense to cache them.<br /><br />2) They are also range of bytes -128 to 127<br /><br />CheersJavin @ Must Override super class method Errorhttp://javarevisited.blogspot.com/2013/02/must-override-superclass-method-java-eclipse.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31982930192054831802013-04-26T07:21:34.377-07:002013-04-26T07:21:34.377-07:00@Anonymous, You are right, good understanding of b...@Anonymous, You are right, good understanding of basic API e.g. java.lang, java.util are extremely important for effective programming in Java. By the way good catch, parseInt() is used for converting String to primitive int :)Javin @ Java Classloder Workinghttp://javarevisited.blogspot.com/2012/12/how-classloader-works-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-4239004076408394152013-04-25T22:24:48.287-07:002013-04-25T22:24:48.287-07:00All these are basic api's and people usually i...All these are basic api's and people usually ignore the internals. But, its too good to know the implementations.<br />Thank you.<br /><br />PS: i think there is a typo "parseInt() method to convert Integer to String"- it should be "to convert String to int"Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-73337010775929862622013-04-25T20:06:41.383-07:002013-04-25T20:06:41.383-07:00Hi,
I don't understand why pool of Integers f...Hi,<br /><br />I don't understand why pool of Integers from -128 to 127 instead of others number ?Danielnoreply@blogger.com