Java #35: How to use the For Each Function to Print

———-Full Source Code———–
//Programmer: Akinwale Owi
//Company: Dagba Computers
//Program Purpose: Print ArrayList Values using the For Each Function

package dagbacomputers;

/**
*
* @author Akin
*/

//imports
import java.util.*;

public class DagbaComputers {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
//Creaation of ArrayList we’ll be Printing from
ArrayListcities = new ArrayList();

//Adding items to list
cities.add(“Tokyo”);
cities.add(“New York”);
cities.add(“Paris”);

//For Each Loop to Print out all values
for (String d: cities)
{
System.out.println(d);//Printing values
}//end of for

}//end of main
}//End of DagbaComputers Class

———-End of Program———

—————Output—————-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: