kinbiko
kinbiko

Reputation: 2165

Groovy range toString() behaviour

I was messing around in the Groovy shell and just happened to try 0..0.toString() I was expecting this to return something like "[0]", as 0..0 == [0], but it gave me an array of integers from 0 to 48. What is going on here?

Upvotes: 2

Views: 138

Answers (1)

Dirk Horsten
Dirk Horsten

Reputation: 3845

The ascii code for the character "0" is 48. With 0..0.toString() you are asking for a list/array staring with the integer 0 (thus it will be a collection of integers), ending with 0.toString(), which groovy succeeds to interpret as an integer by taking its ascii value.

Upvotes: 6

Related Questions