import java.util.ArrayList;
ArrayList<String> names = new ArrayList<>();

int n = names.size();  // Returns n = 3
String s = names.get(0); //Assigns "Emily" to s
String s = names.set(2, "Carolyn"); //Assigns "Cindy" to s, since it was the value that was replaced

Names.add(1, "Ann"); //inserts the element at the given index.  The index shifts to add the given element
String S = names.remove(1); //Removes element at given index.  Element is saved as s.

for (int I = 0; I < names.size(); ++i){

for (String name : names){
	System.out.println(name); //Enhanced For Loop
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter