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?

2
  • Only you can answer if it is fast enough for your purposes. Also, here's a related question 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) Commented Apr 21, 2015 at 5:26
  • thnx for response. I know the this can be done view any cycle. but in my case it's Vector.<String>, there is may be no need to run cycles Commented Apr 21, 2015 at 5:31

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I guess, the last number in each line is time to execute... In my case array length will be <100. one way or enother, I'll have in mind that. tnx for research
Yep, it is a spend time in "ms".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.