John regularly blogs about ColdFusion, JavaScript and other web technologies and contributes to several FOSS projects. His hobbies include writing in the third person. John is a DZone MVB and is not an employee of DZone and has posted 32 posts at DZone. You can read more from them at their website. View Full User Profile

Merging two arrays

  • submit to reddit

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 )>

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!

Published at DZone with permission of John Whish, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Sebastian Mueller replied on Tue, 2011/07/12 - 2:11am

Why is this on the Javalobby frontpage? If it has to be, please do add a "in Coldfusion" to the title when promoting it to the Javalobby frontpage so that it can be discarded by the readers immediately that are not interested in CF - which should be a fairly big number of the audience, I guess.

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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.