Groovy adds to
Map objects the
With this method we can have a String representation of our
We can specify an argument for the maximum width of the generated
Groovy will make sure at least the key/value pairs are added as a pair, before adding three dots (
...) if the maximum size is exceeded.
def course = [ name: 'Groovy 101', teacher: 'mrhaki', location: 'The Netherlands'] assert course.toMapString(15) == '[name:Groovy 101, ...]' assert course.toMapString(25) == '[name:Groovy 101, teacher:mrhaki, ...]'
As mentioned in a previous post we can use the
toListString method to represent a
List as a
def names = ['mrhaki', 'hubert'] assert names.toListString(5) == '[mrhaki, ...]'
Written with Groovy 2.4.7.