1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
All Flashcards
What does the following code output?
java
ArrayList<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
System.out.println(list.size());
2
What does the following code output?
java
ArrayList<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.set(0, 15);
System.out.println(list.get(0));
15
Identify the error in the following code:
java
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
System.out.println(list.get(2));
IndexOutOfBoundsException: The index 2 is out of bounds for the list of size 2.
What does the following code output?
java
ArrayList<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.remove(0);
System.out.println(list.size());
1
What does the following code output?
java
ArrayList<Integer> list = new ArrayList<>();
list.add(5);
list.add(10);
list.add(5);
int index = list.indexOf(5);
System.out.println(index);
0
What does the following code output?
java
ArrayList<String> list = new ArrayList<>();
System.out.println(list.size());
0
Identify the error in the following code:
java
ArrayList<int> list = new ArrayList<>();
ArrayLists cannot store primitive types directly. Use the Integer wrapper class instead: ArrayList
What does the following code output?
java
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.clear();
System.out.println(list.size());
0
What does the following code output?
java
ArrayList<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
System.out.println(list.get(1));
banana
What does the following code output?
java
ArrayList<Integer> list = new ArrayList<>();
list.add(5);
list.add(10);
list.remove(Integer.valueOf(5));
System.out.println(list.size());
1
What is an ArrayList?
A dynamic data structure that stores an ordered collection of items.
What does 'mutable' mean in the context of ArrayLists?
Elements can be changed after the ArrayList is created.
What is a wrapper class?
A class that encapsulates a primitive data type, turning it into an object.
What is linear search?
A method for finding a target element in a list by checking each element sequentially.
Define selection sort.
A sorting algorithm that repeatedly finds the minimum element and moves it to the sorted portion of the list.
Define insertion sort.
A sorting algorithm that inserts each element into its correct position in the already sorted portion of the list.
What is encryption?
The process of converting plain text into a code to protect data from unauthorized access.
What is traversing an ArrayList?
Accessing and processing each element in the ArrayList, usually within a loop.
What is the Java Collections Framework?
A set of interfaces and classes that provide implementations for common data structures.
Define personal data.
Any information that relates to an identifiable individual.
How is ArrayList used in real-world scenarios?
Storing a list of customers in a database or managing a playlist of songs.
How is linear search applied in real-world scenarios?
Finding a specific product in a small inventory list.
How is selection sort applied in real-world scenarios?
Sorting a small list of student names alphabetically.
How is insertion sort applied in real-world scenarios?
Sorting a hand of cards as you receive them in a card game.
How is encryption used to protect user data?
Securing online transactions and protecting sensitive information from hackers.
Give a real-world example of ethical data collection.
A research study that obtains informed consent from participants before collecting their data.
How are ArrayLists used in social media applications?
Storing lists of friends, posts, or comments.
How are ArrayLists used in e-commerce applications?
Managing shopping carts and product lists.
How is data collection used in healthcare?
Tracking patient health records and monitoring disease outbreaks.
How is data collection used in education?
Tracking student performance and personalizing learning experiences.