DevLearningTools

🚧 This site is under active construction — new tools, guides, and pages are added every week.

MODULE 5 · LESSON 11

Lists

ColdFusion lists — delimited strings treated as ordered values. Creating, custom delimiters, listLen, listFirst/listLast/listGetAt, and adding/removing elements.

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

A list in ColdFusion isn't a separate data type the way an array or struct is — it's just a string with a delimiter, treated as an ordered set of values by a family of list functions. Every string is implicitly a list, and every list is implicitly a string.

"Red,Green,Blue" is a list of three elements, separated by commas — the default delimiter. Lists show up constantly in real code: comma-separated form values, URL query parameters, CSV rows, and more.

Learning Objectives

After completing this lesson, you'll be able to:

  • Understand that a list is just a delimited string, not a separate data type.
  • Use a custom delimiter instead of the default comma.
  • Get a list's length and individual elements.
  • Add and remove list elements.

A List Is Just a String

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

colors is an ordinary string variable — nothing marks it as a "list" except that you're calling list functions on it.

Custom Delimiters

The delimiter doesn't have to be a comma — any character works, including ones you wouldn't normally think of as a "list separator," like @ in an email address or . in a file path.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Getting List Elements

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

listRest returns the whole list minus its first element — useful for processing a list one item at a time recursively.

Adding Elements

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Unlike array functions, list functions return a new list rather than modifying the original in place — you need to reassign the result, as shown above.

Removing and Replacing Elements

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Converting Between Lists and Arrays

Covered in the Arrays module — a quick recap, since it's the most common way to move between the two.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Real-World Example: Parsing a File Path

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Treating the file name as a dot-delimited list makes pulling out the extension a one-liner, instead of manual string manipulation.

Common Beginner Mistakes

Forgetting list functions return a new list instead of modifying in place

listAppend(colors, "Blue") on its own doesn't change colors — you need colors = listAppend(colors, "Blue"). This is the opposite of how array functions like arrayAppend behave.

Assuming the delimiter must be a comma

Every list function takes an optional delimiter argument — treat any consistently-separated string (emails, file paths, URLs) as a list with the right delimiter.

Not accounting for empty elements

"a,,b" has an empty element between the two commas. Most list functions skip empty elements by default — pass includeEmptyValues (or similar, function-specific) as true if you need to preserve them.

Best Practices

  • Use lists for genuinely simple, flat, delimited data — reach for an array once you need functions like sort-by-custom-comparator or nested data.
  • Always reassign the result of a list function — nothing happens in place.
  • Pick a delimiter character that won't appear inside the data itself, to avoid accidentally splitting values.

Interview Questions

Is a list a separate data type in ColdFusion?

No — it's just a delimited string. Any string can be treated as a list by calling list functions on it.

What's the default delimiter for list functions?

A comma.

Do list functions modify the original string?

No — they return a new list. You need to reassign the result back to your variable.

How do you get everything in a list except the first element?

listRest(list).

Summary

In this lesson, you learned that a list is just a delimited string, how to use custom delimiters, how to read individual elements, and how to add, remove, and replace list elements.

What's Next?

The next lesson covers searching, sorting, and transforming lists — listFind vs. listContains, listSort, and the functional listMap, listFilter, and listReduce.