我從文件中讀取矩陣,並且所有列都有不同的數據類型。 我無法找到一個結構來保存和操作我的數據。感謝幫助。java中的數據類型和動態綁定
// I read a matrix from file and all column have a different type.
int[] iT = new int[] {1,3,5};
long[] lT = new long[] {123, 456, 789};
double[] dT = new double[] {1.2d, 3.2d, 5.2d};
// I like to know if there are a kind of structure to hold and manipulate it.
Collection<Object[]> collection = new HashSet<Object[]>();
collection.add(iT);
collection.add(dT);
collection.add(lT);
for(Object[] obj : collection) {
String type = obj.getClass().getSimpleName();
switch (type) {
case "double[]":
for(Object element : obj) System.out.println(element);
break;
case "int[]":
for(Object element : obj) System.out.println(element);
break;
case "long[]":
for(Object element : obj) System.out.println(element);
break;
}
}
當然我的代碼不工作;-) –