import java.util.ArrayList; public class ListOfPictures { public static void main(String[] args) { ArrayList
fixed it
import java.util.ArrayList; public class ListOfPictures { public static void main(String[] args) { ArrayListgallery = new ArrayList (); gallery.add(new Picture("degas1.jpg")); gallery.add(new Picture("gaugin1.jpg")); gallery.add(new Picture("monet1.jpg")); gallery.add(new Picture("monet2.jpg")); gallery.add(new Picture("renoir1.jpg")); for(int i = 1; i < gallery.size(); i++) { Picture pic = gallery.get(i); Picture left = gallery.get(i - 1); pic.translate(left.MaxX() + 10, 0); } for (int i = 0; i < gallery.size(); i++) { Picture pic = gallery.get(i); pic.draw(); } } }
Picture old = gallery.get(2); gallery.set(2, gallery.get(1)); gallery.set(1, old); Picture pic = gallery.get(1); gallery.set(2, pic) gallery.add(0, pic) gallery.remove(2); Picture last = gallery.remove(gallery.size() - 1); gallery.add(0, last);
import java.util.ArrayList; public class test { public static void main(String[] args) { ArrayList<String> booksToRead = new ArrayList<String>(); booksToRead.add("The Eyre Affair by Jasper Fforde"); booksToRead.add("Night Watch by Terry Pratchett"); booksToRead.add("Next by Michael Crichton"); booksToRead.add("The Brain That Changes Itself by Norman Doidge"); booksToRead.add("Effective Java by Joshua Bloch"); booksToRead.add("The Visual Display of Quantitative Information by Edward R. Tufte"); String anotherBook = "Why zebras don't get ulcers by Robert M. Sapolsky"; booksToRead.add(2, anotherBook); System.out.println(booksToRead); } }
using "set" for replace
import java.util.ArrayList; public class test { public static void main(String[] args) { ArrayList<String> booksToRead = new ArrayList<String>(); booksToRead.add("The Eyre Affair by Jasper Fforde"); booksToRead.add("Night Watch by Terry Pratchett"); booksToRead.add("Next by Michael Crichton"); booksToRead.add("The Brain That Changes Itself by Norman Doidge"); booksToRead.add("Effective Java by Joshua Bloch"); booksToRead.add("The Visual Display of Quantitative Information by Edward R. Tufte"); String anotherBook = "Why zebras don't get ulcers by Robert M. Sapolsky"; booksToRead.add(2, anotherBook); String sequel = "Lost in a Good Book by Jasper Fforde"; booksToRead.set(0, sequel); // Please don't modify the following line: System.out.println(booksToRead); } }