Assuming that Customer
class has an all-args
constructor Customer(String name, int age, String gender)
and the input array contains all the fields like:
String[] data = {
"Name1", "25", "Male",
"Name2", "33", "Female",
// ...
};
The array of customers may be created and populated like this:
Customer[] customers = new Customer[data.length / 3];
for (int i = 0, j = 0; i < customers.length && j < data.length; i++, j += 3) {
customers[i] = new Customer(data[j], Integer.parseInt(data[j + 1]), data[j + 2]);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…