For loop - like Python range function

后端 未结 9 1581
情歌与酒
情歌与酒 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:40

    Its not available that true. But you make a static method and use it -

    public static int[] range(int index){
        int[] arr = new int[index];
        for(int i=0;i

提交回复
热议问题