How can I see the logic behind how this method converts an integer into a String.
According to this question, Is java an open source programming language? It is. Therefore wouldn't I have access to all the classes?
How can I see the logic behind how this method converts an integer into a String.
According to this question, Is java an open source programming language? It is. Therefore wouldn't I have access to all the classes?
Go to your local zip file and unzip it:
C:\Program Files (x86)\Java\jdk1.7.0_21\src.zip
public static String toString(int i) {
if (i == Integer.MIN_VALUE)
return "-2147483648";
int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
char[] buf = new char[size];
getChars(i, size, buf);
return new String(buf, true);
}
Googling for Integer.toString java code
gave me this link which contains
public String toString() {
return toString(value);
}
You can also find details about toString(int)
there.
Anyway code of standard Java classes is also placed in src.zip
file in your JDK directory. You can also integrate your IDE like Eclipse with this file. This way you will be able to go to code of any method by clicking on it with pressed Ctrl.
Check this http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html
It contains all the methods for integer and how they can be used. If you're looking for a source code for the integer class, I suggest you decompile the jar files or simply search online for it.