ArrayList notes by __________________

  1. What library do you have to import to use an ArrayList? ______________
  2. Given
    –ArrayList<Egg> crate = new ArrayList<Egg>();
    Egg chickie = new Egg();
    crate.add(chickie);
    Egg babyRobin = new Egg();
    crate.add(babyRobin);
    What is:
    crate.size()
    crate.contains(chickie)
    crate.indexOf(chickie)
    crate.isEmpty();
    After crate.remove(chickie);
    What is crate.indexOf(chickie)?
  3. How would you create these arraylists:
    1. To hold numbers with decimal points?
    2. To hold words?
  4. Given ArrayList<Integer> vals = new ArrayList<Integer>();
    What are the contents after each step:
    –vals.add(3);
    –vals.get(1);
    –vals.add(5);
    –vals.set(0,8);
    –vals.remove(0);
  5. •Given:
    ArrayList<String> a = new ArrayList<String>();
    •What is in the list at the end of this code?
    •a.add("a");
    a.add(0,"b");
    •a.set(1,"c");
    •a.add(1,"d");
    •a.add("e");
    •a.remove(1);
  6. What happens if you add a different type of object to a typed ArrayList? _________________
    What is the return type of the ArrayList method size? _________________
  7. ArrayList<String> stringList = new ArrayList<String>();
    stringList.add("thing");
    stringList.add("item");
    What is int index = stringList.indexOf("item"); __________
    for(String item: stringList){
        System.out.print(item.charAt(0)); _____________
    }
  8. 2 ways to tell if an ArrayList is empty:
    1. ____________________________________
    2. ____________________________________
  9. 2 ways to remove something from an ArrayList:
    1. ____________________________________
    2. ____________________________________
  10. Write code to replace the 3rd element in the ArrayList stringList with the word "done"
    _________________________________________