1

我想明智地在 ma app list 中初始化 1000 个字符串

public static final String[] IMAGES = {"1","2","3","4","5","6",......"1000"};
4

3 回答 3

4

当然:

public static final String[] IMAGES;
static {
    IMAGES = new String[1000];
    for (int i = 1; i <= IMAGES.length; ++i) {
        IMAGES[i - 1] = String.valueOf(i);
    }
}
于 2013-08-22T18:46:30.967 回答
1

如果字符串本身只是表示其在数组中位置的整数,则创建数组并运行for循环。

String[] IMAGES = new String[1000];

for(int x = 0; x < IMAGES.length; x++){
    IMAGES[x] = Integer.toString(x);
}
于 2013-08-22T18:47:48.017 回答
1

也许是这样的:

public static final String[] IMAGES;
static {
    IMAGES = new String[1000];
    for (int i = 0; i < IMAGES.length; i++) {
        IMAGES[i] = String.valueOf(i+1);
    }
}
于 2013-08-22T18:53:07.850 回答