Vector 转換成数组的问题
来源:互联网 发布:淘宝店招导航颜色代码 编辑:程序博客网 时间:2024/05/29 02:24
http://blog.csdn.net/treaturebeauty/archive/2005/03/18/323121.aspx
http://topic.csdn.net/t/20020322/09/592486.html
Vector.toArray();
将Vector对象所有元素转换为一个数组输出。
Vector.toArray(Object []);
将Vector对象中所有元素转换为一个数组输出,数组的类型就是参数数组的类型。如果Vector对象中元素类型与参数数组的类型一致,就直接输出;如果Vector对象中元素类型与参数数组的类型<B>不一致</B>,就参照参数数组的类型新建一个数组输出,此新建数组类型与参数数组的类型一致,大小就是Vector的元素个数。
后一种形式的解释原文如下:Returns an array containing all of the elements in this Vector in the correct order. The runtime type of the returned array is that of the specified array. If the Vector fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this Vector.
结论:
(Car[]) cars.toArray();
如果原来cars对象中元素类型不是Car,则在强制转换时会导致类型不匹配的错误。
(Car[]) cars.toArray(new Car[0]);
确保cars对象转换出来的数组就是Car类型,在转换时<B>不会</B>导致类型不匹配的错误。
- Vector 转換成数组的问题
- vector转换成数组
- Image2Lcd图像转换成数组工具遇到的问题
- 集合转换成数组时类型向下转型的问题
- explode将字符串打散成数组后的顺序问题
- 字符串的截取+字符串转换成数组
- js--NodeList转换成数组的方法
- 将arguments转换成数组的方法
- Vector的效率问题
- 嵌套vector的问题
- vector的sort 问题
- vector的初始化问题
- vector的初始化问题
- vector的释放问题
- vector的erase问题
- 关于vector的vector<vector<int>>的使用问题
- ArrayList转换成数组
- 整数反序成数组
- 2009.04.13
- OO系统分析员之路--用例分析系列(7)--用例规约的编写--业务规则和实体描述[整理重发]
- Sharepoint 中读取得不同类型SPField 时的处理方式之一
- Delphi做的软件自动更新
- 2009.04.14
- Vector 转換成数组的问题
- 一次伟大的Web革命书
- Sharepoint 中读取得不同类型SPField 时的处理方式之二
- 9个字中能测出你心仪的人啥时出现?
- PowerDesinger 在PB开发中的应用 随笔
- VS2008 PRO 、WDK 和DDKWizard搭建Vista驱动开发环境
- 如果你不学silverlight:微软很生气,后果很严重,前途很渺茫。
- JMP方法HOOK
- a 的伪类