我想明智地在 ma app list 中初始化 1000 个字符串
public static final String[] IMAGES = {"1","2","3","4","5","6",......"1000"};
当然:
public static final String[] IMAGES;
static {
IMAGES = new String[1000];
for (int i = 1; i <= IMAGES.length; ++i) {
IMAGES[i - 1] = String.valueOf(i);
}
}
如果字符串本身只是表示其在数组中位置的整数,则创建数组并运行for
循环。
String[] IMAGES = new String[1000];
for(int x = 0; x < IMAGES.length; x++){
IMAGES[x] = Integer.toString(x);
}
也许是这样的:
public static final String[] IMAGES;
static {
IMAGES = new String[1000];
for (int i = 0; i < IMAGES.length; i++) {
IMAGES[i] = String.valueOf(i+1);
}
}