-1

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?

Community
  • 1
  • 1
Eddie Martinez
  • 13,582
  • 13
  • 81
  • 106

3 Answers3

1

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);
}
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
  • thanks for the answer should I delete question ? I dont want to get too many downvotes lol – Eddie Martinez Nov 19 '13 at 01:44
  • Your downvotes have been stable for 15 minutes, it's only 1 so I wouldn't bother. Deleting downvoted questions has more negative consequences than leaving them there. The question won't get that many views anymore probably, so there's little chance downvotes will be added. Keep the rules in mind for future questions though, minimal effort is required. – Jeroen Vannevel Nov 19 '13 at 01:45
0

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.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
-1

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.

iWumbo
  • 135
  • 1
  • 8