开发者

How to split an integer in Groovy?

开发者 https://www.devze.com 2023-02-21 19:15 出处:网络
I want to split the given intege开发者_如何转开发r in groovy. Say for example, def a = 198 println(a.split())

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

精彩评论

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