Reputation: 2055
When I collect over a String I was expecting that it
would be of type char
, but it is java.lang.String
. So why is this and how can I collect all characters of a String?
Upvotes: 1
Views: 408
Reputation: 27200
You can do something like this...
someString.collect {
def c = it as char
// carry on...
}
Or...
someString.chars.collect {
// it will be a char
// carry on...
}
Upvotes: 4
Reputation: 50245
In Groovy, a single character is also a String. In order to get each String as a Character use as:
"testString".collect { it as char }
Upvotes: 2