Ofek .T.
Ofek .T.

Reputation: 772

Converting an int to String(Java)

Let's say I run on a for with i from 0 to 6, each run in the for I initialize a class that gets as a parameter a name, ex:

ClassThing[] a = new ClassThing[6];
for (int i=0;i<6;i++)
{
    a[i] = ClassThing( "hello" );
}

So I want each cell to have it's name by the order, a[0].name will be 0, a[1].name will be 1 and on.

How do I use i variable for this?

Thanks.

Upvotes: 1

Views: 201

Answers (2)

Ahmed Adel Ismail
Ahmed Adel Ismail

Reputation: 2184

as said before, you can either use

a[i].name = Integer.toString(i);

or

a[i].name = ""+i;

or any other mentioned way;

Upvotes: 3

M Abbas
M Abbas

Reputation: 6479

You should try something like:

a[i].name = String.valueOf(i)

Upvotes: 3

Related Questions