有没有办法让我的java应用程序根据整数的值在数组中创建一定数量的项目?
编辑:我没有说清楚我的问题。这就是我的意思:这是我的代码:
Loader loader = new Loader();
基本上我想要做的是列出我想在文本文件中调用的构造函数。我的应用程序将读取每一行并将“Loader”替换为我想要调用的构造函数。我已将其设置为将文本文件中的每一行添加到数组中:
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("modEnable.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String str;
ArrayList<String> list = new ArrayList<String>();
try {
while((str = in.readLine()) != null){
list.add(str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] stringArr = list.toArray(new String[0]);
我该怎么做呢?
答案 0 :(得分:0)
你在问这个问题:
public int createArray(int num, int value) {
int[] a = new int[num];
Arrays.fill(a, value);
return a;
}