android - How to optimize declaration of many variables? [Java] -
at moment using this:
d_y1 = double.parsedouble(s_y1); d_y2 = double.parsedouble(s_y2); d_y3 = double.parsedouble(s_y3); d_y4 = double.parsedouble(s_y4); d_y5 = double.parsedouble(s_y5); d_y6 = double.parsedouble(s_y6); d_x1 = double.parsedouble(s_x1); d_x2 = double.parsedouble(s_x2); d_x3 = double.parsedouble(s_x3); d_x4 = double.parsedouble(s_x4); d_x5 = double.parsedouble(s_x5); d_x6 = double.parsedouble(s_x6);
and thought this, wont work: advice?
string[] s_werte = {s_x1, s_x2, s_x3, s_x4, s_x5, s_x6,s_y1, s_y2, s_y3, s_y4, s_y5, s_y6}; double[] d_werte = {d_x1, d_x2, d_x3, d_x4, d_x5, d_x6,d_y1, d_y2, d_y3, d_y4, d_y5, d_y6}; (i = 0; < d_werte.length; i++){ d_werte[i] = double.parsedouble(s_werte[i]); }
if want utilize array cannot initialize variables won't work:
double[] d_werte = {d_x1, d_x2, d_x3, d_x4, d_x5, d_x6,d_y1, d_y2, d_y3, d_y4, d_y5, d_y6};
but need string variable in format can loop like:
string[] strings;
you need first initialize size (and allocate necessary space):
double[] d_werte = new double[12];
or utilize 2 array of 6 length, , assign each value specific index:
for(int = 0; < 12; i++) d_werte[i] = double.parsedouble(strings[i]);
java android arrays optimization
No comments:
Post a Comment