cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1248
Views
0
Helpful
4
Replies

How to sort a multidimensional array in UCCX

kdamisch
Level 1
Level 1

In a UCCX script, I would normally use a Do step to sort a one-dimensional array with this:

Do {

java.util.Arrays Arrays.sort(strInformation);

}

But, now I have a two-dimensional array with values such as this:

strInformation[0][0] = "SALES"

strInformation[0][1] = "32"

strInformation[1][0] = "MARKETING"

strInformation[1][1] = "14

strInformation[2][0] = "SUPPORT"

strInformation[2][1] = "53"

strInformation[3][0] = "FINANCE"

strInformation[3][1] = "34"

I need to sort the array on the 2nd dimension (the numeric values) so it would be in this order:

MARKETING,14

SALES,32

FINANCE,34

SUPPORT,53

Suggestions?

4 Replies 4

Gergely Szabo
VIP Alumni
VIP Alumni

Hi,

if the numeric values are unique, I would create a Map, perhaps a TreeMap with the numbers as keys and strings as values.

But can you please explain why do you need such a structure?

Thanks.

G.

Gergely,

There is potential for both columns to be strings.  I was just using numeric as an example.  I am looping through a db get step to retrieve multiple rows from a stored procedure specified in the db read step.  In a one-dimensional array, I've simply assigned the value retrieved to index [0], then loop through to get the next row and assign that to index [1], and so on.

I now have a requirement where I have multiple values that I need to put in a two-dimensional array as shown in my original post.  So, taking the same db get loop logic, the first row's values would be put into [0][0] and [0][1].  Then, loop through the db get step again to get the next row and assign the values received on that into [1][0] and [1][1], and so on.  Once I loop through all rows (and hit the No Data branch), I need to make sure that this array is sorted on the 2nd column.

I may be able to have the database team change their stored procedure to return the values to UCCX already sorted, but would like to verify it is sorted within my script. Again, I've done this many times on a one-dimensional array, but not on a two-dimensional array.

Thanks!

Kevin

Kevin,

sorry, it's been a long day. Would you mind telling me how this array is being used - I am trying to understand the application from a global point of view.

Thanks in advance.

G.

Samuel Womack
Level 5
Level 5

Just do a manual sort...there are many algorithms out there for this..I've attached an image of the one you always learn in basic programming (Bubble Sort..if there's lotsa data then this method isn't efficient)..