What library do you have to import to use an ArrayList? ______________
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)?
How would you create these arraylists:
To hold numbers with decimal points?
To hold words?
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);
•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);
What happens if you add a different type of object to a typed ArrayList? _________________
What is the return type of the ArrayList method size? _________________
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)); _____________
}
2 ways to tell if an ArrayList is empty:
____________________________________
____________________________________
2 ways to remove something from an ArrayList:
____________________________________
____________________________________
Write code to replace the 3rd element in the ArrayList stringList with the word "done"
_________________________________________