Fill in the blanks for the each loop so we can print the con

Fill in the blanks for the each loop, so we can print the contents of the Arraylist ArrayList list = new ArrayList{}; list.add(\"BIO101\"); list.add(\"cais130\"); list.add(\"cals210\"); list.add(\"csis230\"); list.add(\"CSIS490\"); for {nme: {System.oout.println();}

Solution

Please follow the code and comments for description :

CODE :

class ForEachEx{
   public static void main(String args[]){ // driver method
       int arr[]={12,13,14,44}; // sample array

       for(int i:arr){ // for each loop of the data
           System.out.println(i); // print to console
       }
   }
}

OUTPUT :

12
13
14
44

In the same way for the give code as the array list a string type, the varaible in the for-each loop for the code needs to be of a string type so the blanks in the code are to be replaced as :

for(String name : list) {
   System.out.println(name);
}

Description :

The above code has the initialisation of the variable named name and of the type String datatype for each of the data in the array list named list. The each data saved in the variable name is to be printed so the console data for the next line is to be placed as the variable as name.


Hope this is helpful

 Fill in the blanks for the each loop, so we can print the contents of the Arraylist ArrayList list = new ArrayList{}; list.add(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site