Java: Equivalent of Python's range(int, int)?

后端 未结 14 1820
北荒
北荒 2020-12-02 08:17

Does Java have an equivalent to Python\'s range(int, int) method?

相关标签:
14条回答
  • 2020-12-02 09:00
    public int[] range(int start, int stop)
    {
       int[] result = new int[stop-start];
    
       for(int i=0;i<stop-start;i++)
          result[i] = start+i;
    
       return result;
    }
    

    Forgive any syntax or style errors; I normally program in C#.

    0 讨论(0)
  • 2020-12-02 09:00

    The "Functional Java" library allows to program in such a way to a limited degree, it has a range() method creating an fj.data.Array instance.

    See:

    • http://functionaljava.googlecode.com/svn/artifacts/3.0/javadoc/fj/data/Array.html#range%28int,%20int%29

    Similarly the "Totally Lazy" library offers a lazy range method: http://code.google.com/p/totallylazy/

    0 讨论(0)
提交回复
热议问题