Strings - AP Computer Science Principles
- What method finds a substring's first occurrence in Python?
- find(). Locates initial position of substring occurrence.
- What method converts a string to uppercase in JavaScript?
- toUpperCase(). Converts all letters to uppercase format.
- Identify the function that checks if a character is a digit in Python.
- isdigit(). Returns True if character is numeric digit.
- Identify the method to capitalize the first character of a string in Python.
- capitalize(). Makes first letter uppercase, rest lowercase.
- What method checks if a string contains a specific substring in JavaScript?
- includes(). Checks if substring exists within the string.
- Identify the method to encode a string to UTF-8 in Python.
- encode('utf-8'). Converts string to UTF-8 byte encoding.
- What function converts a string to a float in Python?
- float(). Converts string to decimal number format.
- What function converts a string to a list of characters in Python?
- list(). Creates list with each character as element.
- What function converts an integer to a string in JavaScript?
- toString(). Converts numeric value to string representation.
- Identify the method to convert a string to lowercase in Java.
- toLowerCase(). Built-in method for case conversion in Java.
- State the method to check if a string is empty in JavaScript.
- length property or === ''. Tests length property or compares to empty.
- What function returns the length of a string in most programming languages?
- length() or len(). Standard method to count characters in a string.
- What method converts a string to a float in JavaScript?
- parseFloat(). Converts string to floating-point number.
- State the method to get the character at a specific index in C++.
- at() or []. Accesses individual character by position.
- What method converts a string to uppercase in Python?
- upper(). Transforms all letters to capital case.
- Which method checks the equality of two strings in Java?
- equals(). Compares string content for exact match.
- Identify the method to find the index of a character in a string in Java.
- indexOf(). Returns position of first occurrence of character.
- What method centers a string with a specified width in Python?
- center(). Pads string with spaces for centered alignment.
- State the method to check if a string ends with a specific sequence in Java.
- endsWith(). Tests if string terminates with given suffix.
- Which method gets a substring from a string in JavaScript?
- substring(). Extracts portion of string between indices.
- Which method checks if a string contains only whitespace in Python?
- isspace(). Checks if all characters are whitespace.
- Identify the method to find a substring's last occurrence in Java.
- lastIndexOf(). Finds rightmost position of substring match.
- Find and correct the error: 'Java'.charAt(2) in Python.
- Correct: 'Java'[2]. Python uses bracket notation for character access.
- What function converts a string to an integer in Python?
- int(). Parses string representation into integer value.
- Which function creates a string from a list of characters in Python?
- join(). Combines list elements into single string.
- Which method checks if a string starts with a specific sequence in Python?
- startswith(). Tests if string begins with given prefix.
- Which method can reverse a string in Python?
- slice with [::-1]. Extended slicing with step -1 reverses order.
- What method converts a string to a list of words in Python?
- split(). Breaks string into word array elements.
- Which method splits a string into an array in Python?
- split(). Divides string into array elements by delimiter.
- Identify the method that formats a string in Python.
- format(). Inserts values into string template placeholders.
- State the method to compare two strings lexicographically in Java.
- compareTo(). Performs alphabetical ordering comparison between strings.
- Find and correct the error: 'Hello'.substring(0, 3) in Python.
- Correct: 'Hello'[0:3]. Python uses slice notation instead of substring method.
- Which method concatenates two strings in Python?
- The + operator. Joins strings together using addition operator.
- Which method checks if a string is made of alphabetic characters in Python?
- isalpha(). Validates string contains only letter characters.
- State the method to replace a substring in a string in Java.
- replace(). Substitutes specified text with new text.
- Find and correct the error: 'Hello'.indexOf('e') in Python.
- Correct: 'Hello'.find('e'). Python uses find() instead of indexOf().
- Which method trims whitespace from both ends of a string in Python?
- strip(). Removes leading and trailing whitespace characters.