1

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.

4

2 回答 2

3

如前所述,您可以使用

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

或者

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

或任何其他提及的方式;

于 2013-09-07T20:36:08.920 回答
3

您应该尝试以下方法:

a[i].name = String.valueOf(i)
于 2013-09-07T20:29:27.543 回答