Search code examples
javafor-loopdereference

Dereferencing the integer value of a for loop in java


I just figured out that when I do this in Java:

for(int x = 0; x < 3; x++)
{
    String bla = "bla";
    bla += x.toString();
}

It (Netbeans in this case) will tell me I can not dereference my x integer in such a manner (as I would in C#).

Why is that?


Solution

  • Primitive types are not objects in Java, so you need to use other methods to do that, in this case:

    Integer.toString(x);