2

I need to convert Vector<String> to Array.

I know the this can be done via any cycle. but in my case it's Vector.<String>, there is may be no need to run cycles

At this pont, I guess this is very shor and simple way to do this:

var vector:Vector.<String> = new <String>["111", "111", "111", "111"];
var array:Array = vector.join(",").split(",");

Ofcource, you need to be shure, thet separator will never be the part of any String on Vector. This can force you to set multi-characters separator, like ',,,'. does this effects on speed? Is it ok? Is it fast anough?

SentineL
  • 4,682
  • 5
  • 19
  • 38
  • Only you can answer if it is fast enough for your purposes. Also, here's a related [question](http://stackoverflow.com/questions/1107809/as3-how-to-convert-a-vector-to-an-array) that seems to answer your question as well. personally, i would go with a for loop that just puts the elements in the array (not through push() though, apparently that's slower) –  Apr 21 '15 at 05:26
  • thnx for response. I know the this can be done view any cycle. but in my case it's `Vector.`, there is may be no need to run cycles – SentineL Apr 21 '15 at 05:31

1 Answers1

1

I have tested your function (I called it "short") and the "classic" way with a cycle. Results:

[trace] 10000 elem : classic : 2
[trace] 10000 elem : short : 26
[trace] 100000 elem : classic : 17
[trace] 100000 elem : short : 50
[trace] 1000000 elem : classic : 153
[trace] 1000000 elem : short : 542

So, I can't recommend to use your way on the big data sets, but it will be OK on the small sets of data.

Crabar
  • 1,829
  • 1
  • 14
  • 26