如何初始化值数组一个矢量? [英] How do I initialize a vector with an array of values?
问题描述
我如何初始化向量值的阵列?
我想这和它符合精细,但是还是不行!
LANGS =新矢量<串GT;([EN,FR]);
我还需要加载一个任意阵列插入载体,像这样的:
langlist =EN,FR];
LANGS =新矢量<串GT;(langlist);
有没有办法做到这一点?
编辑:如何初始化一个二维向量的值的二维数组
数= [[10,20,30],[10,20,30];
NUMS =矢量<矢量<数字与GT;>(数字);
我试过,但它给我的错误:
类型错误:错误#1034:类型强制转换失败。
我不认为你可以传递数组的数组中的向量:
矢量<矢量<数>>
该类型强制转换不会为复杂类型的工作。如果你已经拥有了二维数组考虑下面的转换code:
的变种号码:数组= [[1,2,3],[4,5,6]];
VAR numbersTemp:阵列=
numbers.map(
功能(元素:*,指数:INT,编曲:阵列):矢量<数> {
返回矢量<数>(元);
});
VAR NUMS:。矢量<矢量<数>> =矢量<。矢量<数>>(numbersTemp);
当然,这将导致两次创造一切的新副本,因此,最好你是不是转换的大名单。
How do I initialize a vector with an array of values?
I tried this and it complies fine, but does not work!
langs = new Vector.<String>(["en","fr"]);
I also need to load an arbitrary array into a vector, like this:
langlist = ["en","fr"];
langs = new Vector.<String>(langlist);
Is there a way to do this?
Edit: How do I initialize a 2D vector with a 2D array of values?
numbers = [[10,20,30], [10,20,30]];
nums = Vector.<Vector.<Number>>(numbers);
I tried this but it gives me the error:
TypeError: Error #1034: Type Coercion failed
I don't think that you can pass in an array of arrays into the Vector:
Vector.<Vector.<Number>>
The type coercion doesn't work for a complex type. If you already have the 2D Array consider the following conversion code:
var numbers:Array = [[1, 2, 3], [4, 5, 6]];
var numbersTemp:Array =
numbers.map(
function (element:*, index:int, arr:Array):Vector.<Number> {
return Vector.<Number>(element);
});
var nums:Vector.<Vector.<Number>> = Vector.<Vector.<Number>>(numbersTemp);
Of course this will cause new copies of everything to be created twice, so ideally you are not converting big lists.
这篇关于如何初始化值数组一个矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!