In: Computer Science
Make sure you are using the appropriate indentation and styling conventions
Open the online API documentation for the ArrayList class, or the Rephactor Lists topic (or both). You may want to refer to these as you move forward.
Exercise 1 (15 Points)
Exercise 2 (15 Points)
Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark
Exercise 3 (15 Points)
Current size of avengers: xxx
Exercise 4 (15 Points)
Now the size is: xxx
Exercise 5 (20 Points)
Exercise 6 (20 Points)
import java.util.ArrayList;
import java.util.List;
public class ListORama {
private static List<String> avengers;
public static void makeLists(){
avengers=new ArrayList<String>();
}
public static void main(String[] args) {
makeLists();
avengers.add("Chris");
avengers.add("Robert");
avengers.add("Scarlett");
avengers.add("Clark");
avengers.add("Jeremy");
avengers.add("Gwyneth");
avengers.add("Mark");
System.out.println(avengers.toString());
for (String avenger : avengers) {
System.out.println(avenger);
}
System.out.println();
System.out.println("Now the size is:"+avengers.size());
for (int i = 0; i < avengers.size(); i++) {
String string = avengers.get(i);
System.out.println(string);
}
avengers.remove("Clark");
avengers.remove("Gwyneth");
System.out.println("Now the size is:"+avengers.size());
System.out.println(avengers.toString());
avengers.add("Chris H");
avengers.set(0, "Chris E.");
avengers.add(avengers.indexOf("Robert")+1, "Loki");
System.out.println("Now the size is:"+avengers.size());
System.out.println(avengers.toString());
for (int i = 0; i < avengers.size(); i++) {
String string = avengers.get(i);
if(i<avengers.size()-1)
System.out.print(string+",");
else
System.out.print(string);
}
}
}