Is there a Java equivalent of Python's 'enumerate' function?

前端 未结 11 588
别那么骄傲
别那么骄傲 2020-12-08 01:59

In Python, the enumerate function allows you to iterate over a sequence of (index, value) pairs. For example:

>>> numbers = [\"zero\", \"one\", \"tw         


        
11条回答
  •  一生所求
    2020-12-08 02:21

    List list = { "foo", "bar", "foobar"};
    int i = 0;
    for (String str : list){
         System.out.println(i++ + str );
    }
    

提交回复
热议问题