Reputation: 19
In my app I have several groups of variables attributes with their own code. For instance, there are 220 variables, which convert text to numbers:
P1 = Integer.parseInt(S1);
P2 = Integer.parseInt(S2);
...
P220 = Integer.parseInt(S220);
Is it possible to write this code with one or two strings, not with 220? Like this:
Pn = Integer.parseInt(Sn)
, where n - number in the range 1 and 220.
Upvotes: 2
Views: 69
Reputation: 393936
The obvious way would be to use arrays :
int[] S = new String[220];
int[] P = new int[220];
for (int i = 0; i < P.length; i++)
P[i] = Integer.parseInt(S[i]);
It would also simplify the code in which you populate those Strings.
Upvotes: 6