A Better Way to Make a String Array
I was jumping through some hoops to generate a true Java String array in CFML yesterday to pass in to a web service API. Today, while talking to some of the guys on the CF team it came up that there is a really simple way to get an array of Strings in CFML: Use the Java String split() API! Code before: string = CreateObject("java", "java.lang.String"); array = CreateObject("java", "java.lang.reflect.Array"); cookies = array.newInstance(string.getClass(), 3); array.set(cookies, 0, "x=1"); array.set(cookies, 1, "x=2"); array.set(cookies, 2, "x=3"); Code After: s = "x=1,x=2,x=3"; cookies = s.split(","); I would say the second way is much easier.
Read comments or post a reply to : A Better Way to Make a String Array