I have a ArrayList of Clients, can someone please tell me how to write a loop and get each client in the arraylist
List<Client> Clients = new ArrayList<Client>();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a number of ways to implement looping through an ArrayList. The three most common ways used are:
Case 1: The conventional for loop
Use when the index of an element is required. Also useful when you wish to iterate through multiple collections. Can be used to modify the current index element or any element you know the index of. All in all allows the programmer much more control then the methods listed below.
Case 2: The ‘enhanced’ for loop – otherwise known as the ‘for-each’ loop
Enhanced for loops can’t be used for everything; for example they cannot be used to remove elements as you traverse the Collection (the ArrayList in this case), they are also not useful if you are trying to cycle through multiple collections. They’re most useful when you want to go through your ArrayList in first-to-last order and the index of the current element is not required.
Case 3: The iterator approach:
This approach is practically what the enhanced for loop is doing underneath and was added for completeness.