WorksheetsMastering Arrays and Strings
Total questions: 20
Worksheet time: 10mins
What is an array in programming?
An array is a type of function in programming.
An array is a collection of elements identified by index or key.
An array is a single data type variable.
An array is a fixed-size data structure.
How do you declare an array in JavaScript?
let myArray : [1, 2, 3];
const myArray = {1, 2, 3};
var myArray = (1, 2, 3);
let myArray = [1, 2, 3];
What is the difference between a one-dimensional and a multi-dimensional array?
A one-dimensional array is accessed using a string, while a multi-dimensional array uses numbers.
A one-dimensional array is always larger than a multi-dimensional array in size.
A one-dimensional array has a single index for access, while a multi-dimensional array uses multiple indices.
A one-dimensional array can store multiple data types, while a multi-dimensional array only stores one type.
How can you find the length of an array in Python?
Use array_length(array_name) to get the size.
Use len(array_name) to find the length of an array.
Call size(array_name) to determine the length.
Apply count(array_name) for the array length.
What is the purpose of the push() method in arrays?
The push() method removes elements from the beginning of the array.
The push() method sorts the elements of the array in ascending order.
The purpose of the push() method in arrays is to add elements to the end of the array.
The push() method creates a new array from existing elements.
How do you access the first element of an array in C++?
getFirst(arr)
arr.first()
arr[1]
arr[0]
What is string concatenation?
String concatenation is the splitting of a single string into parts.
String concatenation is the conversion of strings to uppercase.
String concatenation is the comparison of two strings for equality.
String concatenation is the joining of two or more strings into one.
How can you convert a string to an array in Java?
String[] array = myString.convertToArray();
String array = myString.toArray();
String[] array = myString.split("delimiter");
String[] array = myString.split();
What is the result of the expression 'Hello'.length in JavaScript?
10
6
4
5
How do you remove the last element from an array in Ruby?
array.remove_last
array.delete_at(-1)
array.shift_last
array.pop
What is the difference between mutable and immutable strings?
Mutable strings are always faster than immutable strings.
Immutable strings can be modified after creation.
Mutable strings cannot be created without a specific function.
Mutable strings can be modified; immutable strings cannot be changed after creation.
How can you split a string into an array in Python?
Invoke the divide() method on the string.
Use the split() method on the string.
Apply the split_string() function to the string.
Use the join() method on the string.
What does the indexOf() method do in JavaScript?
The indexOf() method removes the first occurrence of a specified value from an array.
The indexOf() method returns the first index of a specified value in an array or string, or -1 if not found.
The indexOf() method checks if a value exists in an object and returns true or false.
The indexOf() method adds a specified value to an array or string.
How do you check if an array contains a specific value in Java?
Use Arrays.asList(array).contains(value);
Loop through the array and compare each element with value;
Use array.indexOf(value) to find the value;
Check if value is in array using value.equals(array);
What is the purpose of the map() function in arrays?
The map() function sorts the elements of the array in ascending order.
The map() function merges two arrays into one combined array.
The purpose of the map() function in arrays is to transform each element of the array based on a given function.
The map() function filters elements of the array based on a condition.
How can you reverse a string in C++?
yourString.reverse();
for(int i = 0; i < yourString.size(); i++) { yourString[i] = yourString[yourString.size() - 1 - i]; }
std::swap(yourString);
std::reverse(yourString.begin(), yourString.end());
What is the output of the following code: let arr = [1, 2, 3]; arr[1] = 5; console.log(arr);?
[1, 2, 3, 4]
[1, 2, 5]
[5, 2, 3]
[1, 5, 3]
How do you join elements of an array into a string in Python?
array.join('separator')
''.join(array) or 'separator'.join(array)
array.concat('separator')
stringify(array)
What is a common use case for using arrays?
Displaying images in a gallery.
Sorting data in a database.
Storing a collection of items.
Calculating mathematical equations.
How can you iterate over each character in a string in Java?
for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); }
foreach (char c in str) { }
for (char c : str) { }
while (str.hasNext()) { char c = str.next(); }
