Is there any way to make my java app create a certain number of items in an array based on the value of an integer?
EDIT: I did not make my question clear. Here is what I actually meant:
Here's my code:
Loader loader = new Loader();
Basically what I want to do is list the constructors I want to call in a text file. My app will read each line and replace "Loader" with the constructor that I want to call. I already have it set so that it will add every line in the text file to an array:
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]);
How can I go about doing this?
Are you asking about this:
public int createArray(int num, int value) {
int[] a = new int[num];
Arrays.fill(a, value);
return a;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.