• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ArraySort

Explorer ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

This question was posted in response to the following article: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f14.html

Views

521

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

You cannot sort an array that is returned by a java object. CF errors out. You will have to create a new array and loop-and-append to it then sort your array. Like so

<cfset timezoneClass = createObject( "java", "java.util.TimeZone" ) />

<cfset timezoneIDs = timezoneClass.getAvailableIDs()>

<!--- THIS FAILS --->

<cfset arraysort(timezones,"textnocase")>

<!--- THIS SUCCEEDS --->

<cfset timezones = arraynew(1)>

<cfloop array="#timezoneIDs#" index="tzid" >

          <cfset arrayappend(timezones,tzid)>

</cfloop>

<cfset arraysort(timezones,"textnocase")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

Curious.  In your first example, you set timezoneClass and timezoneIDs, but then try to sort timezones (which, AFAICS, you didn't set.)

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2013 Jan 09, 2013

Copy link to clipboard

Copied

Should have been

<cfset timezoneClass = createObject( "java", "java.util.TimeZone" ) />

<cfset timezoneIDs = timezoneClass.getAvailableIDs()>

<!--- THIS FAILS --->

<cfset arraysort(timezoneIDs,"textnocase")>

<!--- THIS SUCCEEDS --->

<cfset timezones = arraynew(1)>

<cfloop array="#timezoneIDs#" index="tzid" >

          <cfset arrayappend(timezones,tzid)>

</cfloop>

<cfset arraysort(timezones,"textnocase")>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 10, 2013 Jan 10, 2013

Copy link to clipboard

Copied

LATEST

Coldfusion arrays are not Java arrays, but Vector Lists: http://www.bennadel.com/blog/1030-Building-Java-Arrays-In-ColdFusion-Using-Reflection.htm

If you want to sort a Java array, use array.sort(): http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Arrays.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation