Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Blog Post: Keeping Order With Java's LinkedHashMap (With LinkedHashMap Example)
// Some dummy articles yay!
articles = [
{title: "I Am a Title Perhaps", publishDate: createDate(2015, 11, 08)},
{title: "I Am a Title As Well", publishDate: createDate(2014, 08, 15)},
{title: "I Am a Title I Think", publishDate: createDate(2014, 09, 25)},
{title: "I Am a Title", publishDate: createDate(2013, 04, 05)},
{title: "I Am a Title Too", publishDate: createDate(2013, 05, 17)},
{title: "I Am a Title Also", publishDate: createDate(2013, 07, 02)}
LinkedHashMap = createObject("java", "java.util.LinkedHashMap");
collection = LinkedHashMap.init();
for (post in articles) {
year = year(post.publishDate);
if (!structKeyExists(collection, year)) {
collection[year] = LinkedHashMap.init();
if (!structKeyExists(collection[year], monthAsString(month(post.publishDate)))) {
collection[year][monthAsString(month(post.publishDate))] = [];
{"title": post.title, "date": post.publishDate}
<cfloop item="year" collection="#collection#">
<cfloop item="month" collection="#collection[year]#">
<cfloop index="article" array="#collection[year][month]#">
<div>#article.title# | #dateFormat(, "YYYY/MM/DD")#</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.