Choose a collection whose structure fits the task, then track both its values and its valid indices. File reading, changing list sizes, two-dimensional traversal, and recursive traces each add their own conditions to check.
- Personal-data privacy
- Protect people’s information from inappropriate collection, exposure, and use; even records without names may identify someone when combined with other data.
- Example: A published travel log omits names, but exact home locations still reveal individual travelers.
- Data set
- A collection of related pieces of information that can be examined to answer a question.
- Example: A garden’s weekly table lists bed identifiers, watering amounts, and plant heights.
- Array element type
- An array stores elements of one declared type; primitive arrays store primitive values, while object arrays store references.
- Example:
String[] names = new String[2]; creates two slots for String references. - Indexed array traversal
- Use an index that visits the required array positions; indexed access can replace the values stored in those positions.
- Example:
int[] prices={8,12}; for(int slot=0;slot<prices.length;slot++) prices[slot]/=2; halves both stored prices. - Array minimum and maximum
- For a nonempty array, initialize an extreme from an actual element, then compare remaining elements to retain the smallest or largest.
- Example:
int[] a={5,2,9}; int min=a[0]; for(int n:a) if(n<min) min=n; finds 2. - File pathname object
- A File object represents a pathname; creating it alone does not open the file for reading.
- Example:
File path=new File("readings.txt"); represents a pathname, even before any Scanner opens it. - Integer and Double wrappers
- Immutable object types representing int and double values; they allow numeric values to be used where object references are required.
- Example:
Integer count=5; Double rate=1.25; stores references to immutable numeric wrapper objects. - Generic ArrayList
- A resizable ordered collection of object references whose declared type argument specifies the element type; use wrappers for primitive numeric values.
- Example:
ArrayList<String> notes=new ArrayList<String>(); creates an empty list of String references. - Indexed list traversal
- Use indices from zero through the current size minus one to access entries; reason about changed indices whenever insertion or deletion changes the list.
- Example: For a containing “up”, “in”,
for(int i=0;i<a.size();i++) System.out.print(a.get(i)); displays upin. - Array of row arrays
- A two-dimensional array is an array whose elements reference row arrays; each row array contains the values for that row.
- Example:
int[][] grid=new int[2][3]; creates two row arrays, each with three integer slots. - Row-major traversal
- Visit every column within one row before moving to the next row; an indexed version uses rows outside and columns inside.
- Example: For
int[][] g={{1,2},{3,4}};, row-major visitation is 1, 2, 3, 4. - Row or column reduction
- Combine entries from one selected row or column, varying only the other index; initialize separately for each result and guard empty averages.
- Example: For g at least 1×2,
int sum=0; for(int r=0;r<g.length;r++) sum+=g[r][1]; totals that column.