java print each line of a list

Solutions on MaxInterview for java print each line of a list by the best coders in the world

showing results for - "java print each line of a list"
Angela
28 Apr 2017
1//To print each item in a list we use the print line function
2//First we need a list, i will be using an array list to start
3String[] animals = {"dog", "cat", "elephant", "moose"};
4
5//Next we need a way to go trhough each value in the list 1 by 1
6//We will be using a for loop
7
8for(int i = 0; i < animals.size(); i++){
9  //Explaining above: while i is less than the amount of values in the list
10  //AKA the code still has values to check, it will keep looping through the list
11  //Now we just need to print out the values(you can do whatever you want with the values)
12  System.out.println(animals[i]);
13  //The line above prints out a word in the list
14  //Based off of the index(the number assinged to the word) of the word itself
15  //ex. The index for the word cat in the list is 1 (java starts count at 0)
16  //The index being printed in the list is whatever index of the list the loop is currently at
17  //So if the for loop has looped 3 times it will be at elephant
18  
19  //:)
20}
21