按我下面的方式可以分类存储
public class Test2 {
public static void main(String[] args) {
Object objs[] = { 45, "king", 56.45, "rose", 45.4f, true, 'A', false,
"Jack", 56, 0.0, 0.012f, 'B', true, 'C' };
String[] sa = new String[3];
int[] ia = new int[2];
boolean[] ba = new boolean[3];
char[] ca = new char[3];
float[] fa = new float[2];
double[] da = new double[2];
int s = 0, i = 0, b = 0, c = 0, f = 0, d = 0;
for (Object o : objs) {
if (o instanceof String) {
sa[s++] = (String) o;
} else if (o instanceof Integer) {
ia[i++] = (int) o;
} else if (o instanceof Boolean) {
ba[b++] = (boolean) o;
} else if (o instanceof Character) {
ca[c++] = (char) o;
} else if (o instanceof Float) {
fa[f++] = (float) o;
} else if (o instanceof Double) {
da[d++] = (double) o;
}
}
}
} |