开发者

How to split an integer in Groovy?

I want to split the given intege开发者_如何转开发r in groovy. Say for example,

 def a = 198
    println(a.split())

However i get an error, because i could not apply the split method to an integer, so is there any way or method to do this. What i want is this:

   def a = 198
   // what to do here?
   // i want to get an output like 1,9,8
   // any ideas?


You can only split Strings, though what you probably want is to simply do:

"$a".collect { it as Integer }

(which works as String is seen as a Collection of characters)

An alternative is:

"$a"*.toInteger()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜