Best way to get value from Collection by index

前端 未结 10 1551
旧时难觅i
旧时难觅i 2020-12-05 17:08

What is the best way to get value from java.util.Collection by index?

10条回答
  •  被撕碎了的回忆
    2020-12-05 17:35

    You can get the value from collection using for-each loop or using iterator interface. For a Collection c for ( elem: c) System.out.println(elem); or Using Iterator Interface

     Iterator it = c.iterator(); 
            while (it.hasNext()) 
            System.out.println(it.next()); 
    

提交回复
热议问题