Android ArrayList forEach
Ngày đăng:
24/12/2021
Trả lời:
0
Lượt xem:
209
Earlier we shared ArrayList example and how to initialize ArrayList in Java. In this post we are sharing how to iterate (loop) ArrayList in Java. There are four ways to loop ArrayList:
Lets have a look at the below example I have used all of the mentioned methods for iterating list. Output: For Loop 14 7 39 40 Advanced For Loop 14 7 39 40 While Loop 14 7 39 40 Iterator 14 7 39 40In the comment section below, Govardhan asked a question: He asked, how to iterate an ArrayList using Enumeration. Govardhan here is the code: How to iterate arraylist elements using Enumeration interfaceimport java.util.Enumeration; import java.util.ArrayList; import java.util.Collections; public class EnumExample { public static void main(String[] args) { //create an ArrayList object ArrayListOutput: ArrayList elements: C C++ Java DotNet Perl |