我有一個分裂的用戶的年齡分爲8組這樣的Java代碼:我如何優化這段代碼以查看更高性能?
private int[] A0, A1, A2, A3, A4, A5, A6, A7, A8;
public Grouping() {
super();
for (int i = 5; i < 10; i++)
A0[i] = i;
for (int i = 10; i < 20; i++)
A1[i] = i;
for (int i = 20; i < 30; i++)
A2[i] = i;
for (int i = 30; i < 40; i++)
A3[i] = i;
for (int i = 40; i < 50; i++)
A4[i] = i;
for (int i = 50; i < 60; i++)
A5[i] = i;
for (int i = 60; i < 70; i++)
A6[i] = i;
for (int i = 70; i < 80; i++)
A7[i] = i;
for (int i = 10; i < 20; i++)
A8[i] = i;
}
現在我想優化這些代碼。有什麼想法嗎?
...爲*看*更好的性能? – immibis
是的,如果我有A0到A100我不能編碼像上面 –
你想要什麼?更好的性能?更好的可讀性?較短的代碼? A0 ... A8如何使用? – assylias