For loop - like Python range function

后端 未结 9 1580
情歌与酒
情歌与酒 2020-12-30 21:45

I was wondering if in Java there is a function like the python range function.

range(4)

and it would return

[0,1,2,3]
         


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 22:42

    Um... for (int i = 0; i < k; i++)? You don't have to write enhanced for loops all day, you know, although they are cool...

    And just for the sake of argument:

    for (int i : range(k)) char count: 22

    for (int i = 0; i < k; i++) char count: 27

    Discounting the implementation of range, it is pseudo even.

提交回复
热议问题