如题,谢谢了
解决方案 »
- 小弟想问下 有什么工具能把java应用转换成windows程序啊?
- j2se问题!请教高手!
- 急求:从文件中选择需要内容
- 这程序干什么使的啊?请兄弟们赐教啊!
- 大哥,救命啊!,我好多代码不懂,如何提高啊!头发都快掉光了
- 小问题,sun.net和sun.net.ftp.*是包含在SDK里面吗?
- !!!调用yahoo的搜索API!! IE中可以查询 ------附源码
- 兄弟姐妹们,有知道Jboss最大可以承受的日访问量是多少?硬件:p4 2.4G mem:1G
- 新人求教 为什么打印String char字符的时候出现了这种问题?
- 问两道笔试题,关于缓存和线程的
- java图形界面的坐标问题
- Java做tcp客户端的问题
从Vector里面一个一个取出来,然后强制转换装入int类型的数组。
如果存放的数据不能通过转化变成int型的,那就没办法操作了
Vector v = new Vector();
v.add("1");
v.add("2");
int[] ss = new int[2];
for(int i=0;i<2;i++){
ss[i] = Integer.parseInt((String) v.get(i));
System.out.println(ss[i]);
}
}
}
我只是举个例子,这样应该可以的
Vector v = new Vector();
v.add("1");
v.add("2");
int[] ss = new int[2];
for(int i=0;i <2;i++){
ss[i] = Integer.parseInt((String) v.get(i));
System.out.println(ss[i]);
}
}
}
这种方式只能是在知道集合中数据的时候才能啊,还要得到集合length()。size()都可以
// Populate it... Then later, iterate over its elements
Iterator it = vec.iterator ();
while (it.hasNext ()) {
Object o = it.next ();
}
Therefore, when retrieving an object from one of the containers, it can only be returned as a Object type. In most cases, you need to cast the retrieved Object to the specific object type you desire. You should know what kind of objects you store into a container, so you can do the cast correctly.If, however, you cast a returned Object to a type that it does not represent (say, you cast an Integer to a String), the program will fail due to a runtime ClassCastException.