How to iterate through Java List? 4 way to iterate through loop

CrunchifyIterateThroughList Java - Crunchify Tutorial

How to iterate through Java List? This tutorial demonstrates the use of ArrayList, Iterator and a List.

There are 4 ways you can iterate through List.

  1. For Loop
  2. Advanced For Loop
  3. Iterator
  4. While Loop

Here is a sample Java Example.

Output:

Have anything to add to this article? Please chime in and join the conversion.

Enjoyed this post?

Be sure to subscribe to the Crunchify newsletter and get regular updates about awesome posts just like this one and more! Join more than 13000 subscribers!

  • Angel Gutierrez Rodriguez

    What’s the font name? Looks awesome!

    • http://crunchify.com/ App Shah

      Hey Angel – on Crunchify i use

      font-family: 'Noto Sans', sans-serif;
  • Aravinthan K

    Great Tutorial!!. How to iterate List that contains Hashset?

    • http://crunchify.com/ App Shah

      Hi Aravinthan – You could easily convert List to Set and Set to List.

      List to set:

      Set set = new HashSet(list);

      Set to List:

      List list = new ArrayList(set);

      Iterate through list or Set:

      for (String temp : set/list){
              	System.out.println(temp);
              }
  • Gerralt

    Hello App Shah,

    I recently found your site but I wish I found it when I was in the very early stage of learning Java… This site is great! Very nicely done and I’ll recommend this to anyone who wants to learn Java!

    Gerralt

    • http://crunchify.com/ App Shah

      Thanks for stopping by and sharing your thoughts :)

  • http://www.javaexperience.com/ Sandeep

    Nice tutorial. The 4 ways you have shown are really excellent.
    Do let me know your views on my blog post on various topics related to Iterators

    • http://crunchify.com/ App Shah

      Thanks Sandeep for your share…

  • Ricky Thomas

    Awesome Tutorial Crunchify. Found this site recently and I must say very nice work. Keep going.

    • http://crunchify.com/ App Shah

      Awesome.. Thanks Ricky for your comment..