I bet the OP was interested in object initialisation in a C-like fashion, similar to
Object [][] Tbl = {
{ 8, "Aberdeen", "USA", "GMT-06:00", 4416, 72659, 45.45556, -98.41333 },
{ 9, "Aberdeen", "UK", "GMT+00:00", 229, 3091, 57.205, -2.20528 },
{ 10, "Aberporth", "UK", "GMT+00:00", 246, 3502, 52.13944, -4.57111 },
{ 11, "Abidjan", "Côte d'Ivoire", "GMT+00:00", 3867, 65578, 5.25, -3.93333 },
{ 12, "Abilene", "USA", "GMT-06:00", 4328, 72266, 32.41667, -99.68333 },
/* ... */
{ 5128, "Zyryanka", "Russia", "GMT+11:00", 1426, 25400, 65.73333, 150.9 },
};
where the above is meant to initialise a list of instances of a class with mixed-type fields:
class Station {
int id = -1;
String name = null, country = null, timezone = null;
long sta_code = -1, wmo_code = -1;
double latitude = -90.1, longitude = 360.1;
};
(The OP has asked for a single instance only) Yes, it's readily done using java reflection, by adding a varargs constructor that makes use of a reference to the class fields (any error checks are omitted below):
private Field fields[] = this.getClass().getDeclaredFields();
Station(Object... args) {
// fileds.length decremented by one because we must skip
// the last field (i.e., "Field fields[]" itself)
for(int i = 0; i < fields.length-1; i++)
try {
fields[i].set(this, args[i]);
} catch(Exception e) {
e.printStackTrace();
}
}
After that, just add following couple of lines
ArrayList<Station> stList = new ArrayList();
for(Object[] array : Tbl) stList.add(new Station(array));
and use the list as needed. E.g., one can add a method like
void print() {
String s = "";
try {
for(int i = 0; i < fields.length-1; i++)
s += fields[i].getName() + "=" + fields[i].get(this) + " ";
} catch(Exception e) { e.printStackTrace(); }
System.out.println(s);
}
to output the created list:
for (Station st : stList) st.print();
and get
id=8 name=Aberdeen country=USA timezone=GMT-06:00 sta_code=4416 wmo_code=72659 latitude=45.45556 longitude=-98.41333
id=9 name=Aberdeen country=UK timezone=GMT+00:00 sta_code=229 wmo_code=3091 latitude=57.205 longitude=-2.20528
id=10 name=Aberporth country=UK timezone=GMT+00:00 sta_code=246 wmo_code=3502 latitude=52.13944 longitude=-4.57111
id=11 name=Abidjan country=Côte d'Ivoire timezone=GMT+00:00 sta_code=3867 wmo_code=65578 latitude=5.25 longitude=-3.93333
id=12 name=Abilene country=USA timezone=GMT-06:00 sta_code=4328 wmo_code=72266 latitude=32.41667 longitude=-99.68333
...
id=5128 name=Zyryanka country=Russia timezone=GMT+11:00 sta_code=1426 wmo_code=25400 latitude=65.73333 longitude=150.9
Of course, all this is for testing purposes only, and can hardly be recommended for use in the final code.