Merging two arrays
I've mentioned this before in passing in previous posts, but I've just used it to solve a problem and thought it deserved it's own blog post!
The problem I had was that I had two arrays that I want to merge into one. ColdFusion doesn't have an in-built function for merging arrays so you end up having to loop and append one element at a time, which is frankly rubbish! Here's an example:
<cfset foo = [1,2,3]> <cfset bar = [4,5,6]> <cfloop array="#bar#" index="i"> <cfset ArrayAppend( foo, i )> </cfloop>
As we all know, ColdFusion is built on-top of Java, so we can take advantage of this and use some of the Java methods. In short we can get rid of the loop and just do this instead:
<cfset foo = [1,2,3]> <cfset bar = [4,5,6]> <cfset foo.addAll( bar )>
Much nicer!
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Sebastian Mueller replied on Tue, 2011/07/12 - 2:11am
Chung Fang replied on Fri, 2011/08/12 - 4:31am
The following paragraphs summarize the work of Cert Sites experts who are completely familiar with all the aspects of Cert Sites. Heed their advice to avoid any Cert Sites surprises.
Truthfully, the only difference between you and Cert Sites experts is time. If you'll invest a little more time in reading, you'll be that much nearer to expert status when it comes to Cert Sites.
What I am searching for is adolescent humans of access in our community pass4sure 1z0-042. I am alive on ambience up an Advisory Council that will serve as consultants and connectors for the project pass4sure COG-112. I would adulation to acquisition a (or several) motivated, affiliated adolescent humans from the association who affliction about the affair of advantageous sexuality pass4sure PMI-002. Adolescent parents would be a plus! Part of the access that Real Life. Real Talk. takes is that we charge non-traditional partners, including the business community, to accouterment this issue.
Knowing enough about Cert Sites to make solid, informed choices cuts down on the fear factor. If you apply what you've just learned about Cert Sites, you should have nothing to worry about.