Question

In String Template one can easily get an element of a Java Map within the template. Is it possible to get the n-th element of an array in a similar way?

According to the String Template Cheat Sheet you can easily get the first or second element:

You can combine operations to say things like first(rest(names)) to get second element.

but it doesn't seem possible to get the n-th element easily. I usually transform my list into a map with list indexes as keys and do something like

map.("25")

Is there some easier/more straightforward way?

Was it helpful?

Solution

Sorry, there is no mechanism to get a[i].

OTHER TIPS

There is no easy way getting n-th element of the list.

In my opinion this indicates that your view and business logic are not separated enough: knowledge of what magic number 25 means is spread in both tiers.

One possible solution might be converting list of values to object which provides meaning to the elements. For example, lets say list of String represents address lines, in which case instead of map.("3") you would write address.street.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top