Home
Subjects
Textbook solutions
Create
Study sets, textbooks, questions
Log in
Sign up
Upgrade to remove ads
Only $35.99/year
Science
Computer Science
Data Structures
Grouping objects
STUDY
Flashcards
Learn
Write
Spell
Test
PLAY
Match
Gravity
Terms in this set (17)
What do collection classes do?
store collections of objects (undefined size & can dynamically change)
What does import java.util.ArrayList do?
imports ArrayList class from java.util package so it can be used
What does private ArrayList<String> files; do?
creates the field that stores the ArrayList but not the ArrayList itself. The type of the field is ArrayList<String> (arraylist of string)
ArrayList is the type of the collection
<String> is the type of the objects the collection will contain
What does files = new ArrayList<>(); do?
creates an empty ArrayList with no elements but can now store elements.
type parameter can be inferred from the variable being assigned to- files is declared as string so ArrayList element type is string
What are the features of the collection ArrayList?
increases its capacity as necessary
keeps a private count: size() accessor —> keeps track of how many elements it has
keeps the objects in order (starts from 1)
can only store 1 specific type (e.g. all String, all of class Person)- homogenous
no gaps- indexes get shifted
What does the index numbering of a collection start as?
index numbering of collections starts from 0
What happens if you try to get an element that doesn't exist?
(logic error)- program crashes
What are java's class libraries called?
packages
What are the main ArrayList methods?
add, get, remove, size
What type is ArrayList?
parameterized/generic type
What is iteration?
iteration- perform an action an arbitrary amount of times- use loops e.g. for-each loop
What is the format for a for each loop?
for (ElementType element: collection) {loop body}
For a for each loop what must the type of the element be?
type of element (local variable) must be the same as elements of the collection- elements in the collection are taken out 1 by one & assigned to that element
How many times the the for each loop jump back up?
end of loop jumps back up for as many elements as there are in collection e.g. 0 elements = loop is executed 0 times
What does the .contains() method do?
method of string class, sees if part of the string matches another string
What are some critiques of the for each loop?
easy to write
termination happens naturally (collection is never infinite)
collection cannot be changed by the actions (e.g. cannot remove elements from a collection as you iterate)
no index provided- not all collections are index-based
can't stop part way through
provides a 'definite iteration' aka 'bounded iteration'- know how many times it will loop
When using the for-each loop how many times is an object in the collection available?
every object in the collection is made available exactly once to the loop's body
Sets found in the same folder
4 Recursion
21 terms
Building GUIs, Part 1
55 terms
Classes & objects
20 terms
9 Working in Teams
13 terms
Other sets by this creator
9 Making the most of models
14 terms
8 Agile Software Development
84 terms
10 Sorting Algorithms
21 terms
9 Search Tree Structures
10 terms