AP Computer Science a Flashcards: Introduction To Using Data Sets

Study Introduction To Using Data Sets in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Introduction To Using Data Sets

0 mastered0 still learning

0% Complete

QUESTION
1/ 73

What is an alternative to arrays for dynamic data storage?

Tap card or press Space to flip

ANSWER

ArrayList. Provides dynamic resizing capabilities that arrays lack.

How well did you know it?

Card 1 / 73

What this deck covers

This deck focuses on Introduction To Using Data Sets, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: What is an alternative to arrays for dynamic data storage?

Answer: ArrayList. Provides dynamic resizing capabilities that arrays lack.

Flashcard 2: Identify the error: int[] arr = new int[5]{1, 2, 3, 4, 5};

Answer: Remove size: int[] arr = {1, 2, 3, 4, 5};. Cannot specify size when using array literal initialization syntax.

Flashcard 3: How do you declare a String array with specific values?

Answer: String[] array = {"value1", "value2"};. Array literal syntax works for String objects like other types.

Flashcard 4: Which class provides static methods for manipulating arrays?

Answer: java.util.Arrays. Contains utility methods like sort(), toString(), and copyOf().

Flashcard 5: Identify the error: int[] arr = new int[3]; arr[3] = 10;

Answer: Access beyond bounds; valid indices are 0 to 2. Index 3 exceeds bounds since valid indices are 0, 1, 2.

Flashcard 6: What is the default value for elements in a boolean array?

Answer: false. Boolean arrays initialize to false, unlike numeric arrays (zero).

Flashcard 7: What is the time complexity of accessing an element in an array?

Answer: O(1)O(1). Direct index-based access provides constant time complexity.

Flashcard 8: How do you access the element at row 2, column 3 in a 2D array 'array'?

Answer: array[1][2]. First index is row, second index is column in 2D arrays.

Flashcard 9: What does 'array.length' return for a 2D array?

Answer: The number of rows. First dimension represents rows; use array[i].length for columns.

Flashcard 10: State the purpose of the 'Arrays.toString()' method.

Answer: Converts array to a readable string format. Formats array contents as [element1, element2, ...] for debugging.

Flashcard 11: What is the time complexity of sorting an array using Arrays.sort()?

Answer: O(n×log(n))O(n \times \text{log}(n)). Uses efficient dual-pivot quicksort algorithm for optimal performance.

Flashcard 12: How do you find the maximum value in an integer array 'arr'?

Answer: Use a loop or Arrays.stream(arr).max().getAsInt();. Manual loop or stream API provides maximum value efficiently.

Flashcard 13: Which exception is thrown for accessing an invalid array index?

Answer: ArrayIndexOutOfBoundsException. Specific runtime exception for array bounds violations.

Flashcard 14: How do you initialize an array with values 1, 2, 3 in Java?

Answer: int[] array = {1, 2, 3};. Array literal syntax that creates and initializes in one step.

Flashcard 15: What method is used to sort an array in Java?

Answer: Arrays.sort(array);. Utility method that sorts elements in ascending order using quicksort.

Flashcard 16: What keyword is used to create an instance of an array?

Answer: new. Required keyword for dynamic memory allocation of array objects.

Flashcard 17: What is the difference between an array and an ArrayList?

Answer: ArrayList can dynamically resize; arrays have fixed size. ArrayList grows automatically while arrays have fixed capacity.

Flashcard 18: State the syntax to access the third element of an array named 'arr'.

Answer: arr[2]. Uses zero-based indexing, so index 2 represents the third element.

Flashcard 19: Which data type can an array hold?

Answer: Arrays can hold any primitive or object type. Supports primitives (int, char) and reference types (String, Object).

Flashcard 20: Which class provides static methods for manipulating arrays?

Answer: java.util.Arrays. Contains utility methods like sort(), toString(), and copyOf().

Flashcard 21: What is the default value of an int array element in Java?

Answer:

  1. Java initializes numeric array elements to zero by default.

Flashcard 22: State the syntax to access the third element of an array named 'arr'.

Answer: arr[2]. Uses zero-based indexing, so index 2 represents the third element.

Flashcard 23: How do you check if two arrays 'a' and 'b' are equal?

Answer: Arrays.equals(a, b). Compares elements pairwise rather than reference equality.

Flashcard 24: What is an array in Java?

Answer: A data structure to store multiple values of the same type. Allows efficient storage and access to multiple values using indices.

Flashcard 25: How do you declare a 2D integer array with 3 rows and 4 columns?

Answer: int[][] array = new int[3][4];. Allocates space for a rectangular grid with specified dimensions.

Flashcard 26: How do you copy an array 'arr' into a new array 'copy'?

Answer: int[] copy = Arrays.copyOf(arr, arr.length);. Creates a shallow copy with the same length as original.

Flashcard 27: How do you declare an integer array of size 10 in Java?

Answer: int[] array = new int[10];. Creates an array with 10 integer slots, all initially zero.

Flashcard 28: Identify the index of the first element in an array.

Answer:

  1. Java uses zero-based indexing for all arrays.

Flashcard 29: What is the primary advantage of using arrays?

Answer: Efficient access and storage of elements of the same type. Constant-time access and contiguous memory allocation improve performance.

Flashcard 30: What is a common use case for 2D arrays?

Answer: Representing matrices or grids. Ideal for tabular data like game boards or spreadsheets.

Flashcard 31: How do you iterate over an array 'arr' using a for-each loop?

Answer: for (int element : arr) { }. Enhanced for loop syntax that iterates without index management.

Flashcard 32: What is the primary advantage of using arrays?

Answer: Efficient access and storage of elements of the same type. Constant-time access and contiguous memory allocation improve performance.

Flashcard 33: Identify the index of the first element in an array.

Answer:

  1. Java uses zero-based indexing for all arrays.

Flashcard 34: Which method converts an array to a list?

Answer: Arrays.asList(array). Returns fixed-size list backed by the original array.

Flashcard 35: Which exception is thrown for accessing an invalid array index?

Answer: ArrayIndexOutOfBoundsException. Specific runtime exception for array bounds violations.

Flashcard 36: How do you copy an array 'arr' into a new array 'copy'?

Answer: int[] copy = Arrays.copyOf(arr, arr.length);. Creates a shallow copy with the same length as original.

Flashcard 37: State the purpose of the 'System.arraycopy()' function.

Answer: Copies elements from one array to another. System method for efficient bulk array element transfer.

Flashcard 38: How do you declare a 2D integer array with 3 rows and 4 columns?

Answer: int[][] array = new int[3][4];. Allocates space for a rectangular grid with specified dimensions.

Flashcard 39: Which method converts an array to a list?

Answer: Arrays.asList(array). Returns fixed-size list backed by the original array.

Flashcard 40: What method is used to sort an array in Java?

Answer: Arrays.sort(array);. Utility method that sorts elements in ascending order using quicksort.

Flashcard 41: How do you determine the length of a string in Java?

Answer: string.length(). String method (with parentheses) unlike array.length property.

Flashcard 42: How do you create a reference to an existing array 'arr'?

Answer: int[] newRef = arr;. Creates alias pointing to same memory location, not a copy.

Flashcard 43: How do you reverse an array 'arr' in Java?

Answer: Use a loop to swap elements or Collections.reverse(Arrays.asList(arr));. Multiple approaches exist since arrays lack built-in reverse method.

Flashcard 44: How do you initialize an array with values 1, 2, 3 in Java?

Answer: int[] array = {1, 2, 3};. Array literal syntax that creates and initializes in one step.

Flashcard 45: Identify the error: int[] arr = new int[5]{1, 2, 3, 4, 5};

Answer: Remove size: int[] arr = {1, 2, 3, 4, 5};. Cannot specify size when using array literal initialization syntax.

Flashcard 46: State the purpose of the 'Arrays.toString()' method.

Answer: Converts array to a readable string format. Formats array contents as [element1, element2, ...] for debugging.

Flashcard 47: How do you find the maximum value in an integer array 'arr'?

Answer: Use a loop or Arrays.stream(arr).max().getAsInt();. Manual loop or stream API provides maximum value efficiently.

Flashcard 48: State the purpose of the 'System.arraycopy()' function.

Answer: Copies elements from one array to another. System method for efficient bulk array element transfer.

Flashcard 49: What is an ArrayIndexOutOfBoundsException?

Answer: An error when accessing an index outside the array's bounds. Runtime exception thrown when index is negative or >= length.

Flashcard 50: How do you determine the length of a string in Java?

Answer: string.length(). String method (with parentheses) unlike array.length property.

Flashcard 51: How do you check if two arrays 'a' and 'b' are equal?

Answer: Arrays.equals(a, b). Compares elements pairwise rather than reference equality.

Flashcard 52: Identify the output: int[] arr = {10, 20}; System.out.println(arr[1]);

Answer:

  1. Accesses the second element (index 1) which contains value 20.

Flashcard 53: How do you iterate over an array 'arr' using a for-each loop?

Answer: for (int element : arr) { }. Enhanced for loop syntax that iterates without index management.

Flashcard 54: What is the syntax to declare a char array in Java?

Answer: char[] array = new char[size];. Character array declaration follows same pattern as other types.

Flashcard 55: How do you access the element at row 2, column 3 in a 2D array 'array'?

Answer: array[1][2]. First index is row, second index is column in 2D arrays.

Flashcard 56: Which data type can an array hold?

Answer: Arrays can hold any primitive or object type. Supports primitives (int, char) and reference types (String, Object).

Flashcard 57: Identify the output: int[] arr = {10, 20}; System.out.println(arr[1]);

Answer:

  1. Accesses the second element (index 1) which contains value 20.

Flashcard 58: How do you reverse an array 'arr' in Java?

Answer: Use a loop to swap elements or Collections.reverse(Arrays.asList(arr));. Multiple approaches exist since arrays lack built-in reverse method.

Flashcard 59: State the method to fill an array with a specific value.

Answer: Arrays.fill(array, value);. Efficiently sets all array elements to the specified value.

Flashcard 60: What is an alternative to arrays for dynamic data storage?

Answer: ArrayList. Provides dynamic resizing capabilities that arrays lack.

Flashcard 61: What is the syntax to declare a char array in Java?

Answer: char[] array = new char[size];. Character array declaration follows same pattern as other types.

Flashcard 62: State the method to fill an array with a specific value.

Answer: Arrays.fill(array, value);. Efficiently sets all array elements to the specified value.

Flashcard 63: Identify the error: int[] arr = new int[3]; arr[3] = 10;

Answer: Access beyond bounds; valid indices are 0 to 2. Index 3 exceeds bounds since valid indices are 0, 1, 2.

Flashcard 64: How do you declare a String array with specific values?

Answer: String[] array = {"value1", "value2"};. Array literal syntax works for String objects like other types.

Flashcard 65: What is a 2D array?

Answer: An array of arrays, often used for matrices. Each element is itself an array, creating rows and columns.

Flashcard 66: What keyword is used to create an instance of an array?

Answer: new. Required keyword for dynamic memory allocation of array objects.

Flashcard 67: What is a common use case for 2D arrays?

Answer: Representing matrices or grids. Ideal for tabular data like game boards or spreadsheets.

Flashcard 68: What does 'array.length' return for a 2D array?

Answer: The number of rows. First dimension represents rows; use array[i].length for columns.

Flashcard 69: How do you create a reference to an existing array 'arr'?

Answer: int[] newRef = arr;. Creates alias pointing to same memory location, not a copy.

Flashcard 70: What is the difference between an array and an ArrayList?

Answer: ArrayList can dynamically resize; arrays have fixed size. ArrayList grows automatically while arrays have fixed capacity.

Flashcard 71: What is the default value for elements in a boolean array?

Answer: false. Boolean arrays initialize to false, unlike numeric arrays (zero).

Flashcard 72: What is the time complexity of sorting an array using Arrays.sort()?

Answer: O(n×log(n))O(n \times \text{log}(n)). Uses efficient dual-pivot quicksort algorithm for optimal performance.

Flashcard 73: What is an ArrayIndexOutOfBoundsException?

Answer: An error when accessing an index outside the array's bounds. Runtime exception thrown when index is negative or >= length.