<p>Using CFML (ColdFusion Markup Langauge, aka ColdFusion), how can you compare if two single dimension arrays are the same?</p>

[{'answer_id': 30292, 'author': 'Jason', 'author_id': 3242, 'author_profile': 'https://Stackoverflow.com/users/3242', 'pm_score': 4, 'selected': False, 'text': '<p>There\'s a very simple way of comparing two arrays using CFML\'s underlying java. According to a recent blog by Rupesh Kumar of Adobe (<a href="http://coldfused.blogspot.com/" rel="nofollow noreferrer">http://coldfused.blogspot.com/</a>), ColdFusion arrays are an implementation of java lists (java.util.List). So all the Java list methods are available for CFML arrays.</p>\n\n<p>So to compare 2 arrays all you need to do is use the equals method. It returns a YES if the arrays are equal and NO if they are not.</p>\n\n<pre><code>&lt;cfset array1 = listToArray("tom,dick,harry,phred")/&gt;\n&lt;cfset array2 = listToArray("dick,harry,phred") /&gt;\n&lt;cfset array3 = listToArray("tom,dick,harry,phred")/&gt;\n\n&lt;cfoutput&gt;\nArray2 equals Array1 #array2.equals(array1)# (returns a NO) &lt;br/&gt;\nArray3 equals Array1 #array3.equals(array1)# (returns a YES) &lt;br/&gt;\n&lt;/cfoutput&gt;\n</code></pre>\n'}, {'answer_id': 36257, 'author': 'philcruz', 'author_id': 3784, 'author_profile': 'https://Stackoverflow.com/users/3784', 'pm_score': 2, 'selected': False, 'text': '<p>The arrayCompare() user-defined function at cflib should do it\n<a href="http://cflib.org/index.cfm?event=page.udfbyid&amp;udfid=1210" rel="nofollow noreferrer" title="arrayCompare()">http://cflib.org/index.cfm?event=page.udfbyid&amp;udfid=1210</a></p>\n'}, {'answer_id': 43962, 'author': 'James Marshall', 'author_id': 1025, 'author_profile': 'https://Stackoverflow.com/users/1025', 'pm_score': 2, 'selected': False, 'text': "<p>Jasons answer is certainly the best, but something I've done before is performed a hash comparison on objects  that have been serialised to WDDX.</p>\n\n<p>This method is only useful for relatively small arrays, but it's another option if you want to keep it purely CFML. It also has the benefit that you can apply the method to other data types as well...</p>\n\n<p>Edit: Adams' entirely right (as you can see from his numbers) - JSON is much more economical, not only in this situation, but for serialization in general. In my defense I'm stuck using CFMX 6.1 that has no inbuilt JSON functions, and was trying to avoid external libs.</p>\n"}, {'answer_id': 50313, 'author': 'Adam Tuttle', 'author_id': 751, 'author_profile': 'https://Stackoverflow.com/users/751', 'pm_score': 2, 'selected': False, 'text': '<p>To build on James\' answer, I thought that JSON might be preferrable over WDDX. In fact, it proves to be considerably more efficient. Comparing hashes is not that expensive, but serializing the data and then generating the hash could be (for larger and/or more complex data structures).</p>\n\n<pre><code>&lt;cfsilent&gt;\n    &lt;!--- create some semi-complex test data ---&gt;\n    &lt;cfset data = StructNew() /&gt;\n    &lt;cfloop from="1" to="50" index="i"&gt;\n        &lt;cfif variables.i mod 2 eq 0&gt;\n            &lt;cfset variables.data[variables.i] = StructNew()/&gt;\n            &lt;cfset tmp = variables.data[variables.i] /&gt;\n            &lt;cfloop from="1" to="#variables.i#" index="j"&gt;\n                &lt;cfset variables.tmp[variables.j] = 1 - variables.j /&gt;\n            &lt;/cfloop&gt;\n        &lt;cfelseif variables.i mod 3 eq 0&gt;\n            &lt;cfset variables.data[variables.i] = ArrayNew(1)/&gt;\n            &lt;cfset tmp = variables.data[variables.i] /&gt;\n            &lt;cfloop from="1" to="#variables.i#" index="j"&gt;\n                &lt;cfset variables.tmp[variables.j] = variables.j mod 6 /&gt;\n            &lt;/cfloop&gt;\n            &lt;cfset variables.data[variables.i] = variables.tmp /&gt;\n        &lt;cfelse&gt;\n            &lt;cfset variables.data[variables.i] = variables.i /&gt;\n        &lt;/cfif&gt;\n    &lt;/cfloop&gt;\n&lt;/cfsilent&gt;\n\n&lt;cftimer label="JSON" type="inline"&gt;\n    &lt;cfset jsonData = serializeJson(variables.data) /&gt;\n    &lt;cfset jsonHash = hash(variables.jsonData) /&gt;\n    &lt;cfoutput&gt;\n        JSON: done.&lt;br /&gt;\n        len=#len(variables.jsonData)#&lt;br/&gt;\n        hash=#variables.jsonHash#&lt;br /&gt;\n    &lt;/cfoutput&gt;\n&lt;/cftimer&gt;\n&lt;br/&gt;&lt;br/&gt;\n&lt;cftimer label="WDDX" type="inline"&gt;\n    &lt;cfwddx action="cfml2wddx" input="#variables.data#" output="wddx" /&gt;\n    &lt;cfset wddxHash = hash(variables.wddx) /&gt;\n    &lt;cfoutput&gt;\n        WDDX: done.&lt;br /&gt;\n        len=#len(variables.wddx)#&lt;br/&gt;\n        hash=#variables.wddxHash#&lt;br /&gt;\n    &lt;/cfoutput&gt;\n&lt;/cftimer&gt;\n</code></pre>\n\n<p>Here\'s the output that the above code generates on my machine:</p>\n\n<pre><code>JSON: done.\nlen=7460\nhash=5D0DC87FDF68ACA4F74F742528545B12\nJSON: 0ms\n\nWDDX: done.\nlen=33438\nhash=94D9B792546A4B1F2FAF9C04FE6A00E1\nWDDX: 47ms\n</code></pre>\n\n<p>While the data structure I\'m serializing is fairly complex, it could easily be considered small. This should make the efficiency of JSON serialization over WDDX even more preferrable.</p>\n\n<p>At any rate, if I were to try to write a "compareAnything" method using hash comparison, I would use JSON serialization over WDDX.</p>\n'}, {'answer_id': 63901, 'author': 'kooshmoose', 'author_id': 7436, 'author_profile': 'https://Stackoverflow.com/users/7436', 'pm_score': 2, 'selected': False, 'text': '<p>I was looking into using CF\'s native Java objects awhile back and this question reminded me of a few blog posts that I had bookmarked as a result of my search.</p>\n\n<blockquote>\n  <p>ColdFusion array is actually an implementation of java list (java.util.List). So all the list methods are actually available for Array.\n  CF provides most of the list functionality using Array functions but there are few things possible with java list which you can not do directly with CF functions. </p>\n  \n  <ol>\n  <li>Merge two arrays</li>\n  <li>Append an array in the middle of another array</li>\n  <li>Search for an element in an array</li>\n  <li>Search array 1 to see if array 2\'s elements are all found</li>\n  <li>Equality check</li>\n  <li>Remove elements in array 1 from array 2</li>\n  </ol>\n  \n  <p>From: <a href="http://coldfused.blogspot.com/2007/01/extend-cf-native-objects-harnessing.html" rel="nofollow noreferrer">http://coldfused.blogspot.com/2007/01/extend-cf-native-objects-harnessing.html</a></p>\n</blockquote>\n\n<p>Another resource I found shows how you can use the native Java Array class to get unique values and to create custom sorts functions in case you need to sort an array of dates, for instance.</p>\n\n<p><a href="http://www.barneyb.com/barneyblog/2008/05/08/use-coldfusion-use-java/" rel="nofollow noreferrer">http://www.barneyb.com/barneyblog/2008/05/08/use-coldfusion-use-java/</a></p>\n\n<p>This second link contains links to other posts where the author shows how to use other Java classes natively to gain either functionality or speed over CF functions.</p>\n'}, {'answer_id': 81428, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>All of these solutions check that two arrays are equal. They don't check that they are the same object. The only way I know to do that in native CF is to change the object in some way and see if both references have the change in. </p>\n\n<p>I also think that you should be wary of relying on CF implementing certain java classes or exposing methods. These are liable to change. </p>\n\n<p>As for comparing two arrays to see if the contents is the same, why not just \n Check the length (if different return false)\n If the lengths are the same from 1 to array len and check the elements are the same break and return false if they are not.</p>\n\n<p>This will work for simple values.</p>\n"}, {'answer_id': 130971, 'author': 'ale', 'author_id': 21960, 'author_profile': 'https://Stackoverflow.com/users/21960', 'pm_score': 3, 'selected': True, 'text': '<p>Assuming all of the values in the array are simple values, the easiest thing might be to convert the arrays to lists and just do string compares.</p>\n\n<pre><code>&lt;cfif arrayToList(arrayA) IS arrayToList(arrayB)&gt;\n    Arrays are equal!\n&lt;/cfif&gt;\n</code></pre>\n\n<p>Not as elegant as other solutions offered, but dead simple.</p>\n'}]
['https://Stackoverflow.com/questions/30288', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3242/']